(\\\\*))\n/e", "str_repeat('
\n',mb_strlen('$1'))", "str_repeat('\n',mb_strlen('$1'))", "ligne1\\\\\nligne2"); // * unordered list MiniWiki::Markup("/(^|\n)\*(([^\n]*(\n|$))(\*[^\n]*(\n|$))*)/se", "'

'", "'$1 -' . str_replace(\"\\n*\", \"\\n -\", '$2')", "* element1\n* element2\n* element3"); // # unordered list MiniWiki::Markup("/(^|\n)#(([^\n]*(\n|$))(#[^\n]*(\n|$))*)/se", "'

  1. '.str_replace(\"\\n#\",'
  2. ','$2').'
'", "'$0'", "# element1\n# element2\n# element3"); // bold, italic and others // ''' bold ''' MiniWiki::Markup("/'''(.*?)'''/",'$1','*$1*', "'''gras'''"); // '' italic '' MiniWiki::Markup("/''(.*?)''/",'$1','/$1/', "''italique''"); // '+ big +' MiniWiki::Markup("/'\\+(.*?)\\+'/",'$1','*$1*', "'+grand+'"); // '- small -' MiniWiki::Markup("/'\\-(.*?)\\-'/",'$1','$1', "'-petit-'"); // '^superscript^' MiniWiki::Markup("/'\\^(.*?)\\^'/",'$1','$1', "'^exposant^'"); // '_subscript_' MiniWiki::Markup("/'_(.*?)_'/",'$1','$1', "'_indice_'"); // {+ underline +} MiniWiki::Markup("/\\{\\+(.*?)\\+\\}/",'$1','_$1_', "{+insertion+}"); // {- strikeout -} MiniWiki::Markup("/\\{-(.*?)-\\}/",'$1','-$1-', "{-suppression-}"); // {color| colored text |} MiniWiki::Markup("/%([a-z]+|\#[0-9a-f]{3,6})%(.*?)%%/i", "$2", "$2", "%red% texte en rouge %%\\\\\n%#ff0% texte en jaune %%\\\\\n%#0000ff% texte en bleu %%"); // [+ big +] [++ bigger ++] [+++ even bigger +++] ... MiniWiki::Markup("/\\[(([-+])+)(.*?)\\1\\]/e","'$3'", "'$3'", "[+ grand +]\n\n[++ plus grand ++]\n\n[+++ encore plus grand +++]"); // -----
MiniWiki::Markup("/(\n|^)--(--+| \n)/s", '$1
', '$1-- '."\n", "----\n"); // titles MiniWiki::$title_index = MiniWiki::Markup('/(\n|^)(!+)([^\n]*)/se', "'$1$3'", "'$1$3'", "!titre1\n\n!!titre2\n\n!!!titre3"); // links MiniWiki::Markup('/((?:https?|ftp):\/\/(?:[\.\,\;\!\:]*[\w@~%$£µ&i#\-+=_\/\?])*)/ui', '\\0', '<\\0>'); MiniWiki::Markup('/(\s|^|\[\[)www\.((?:[\.\,\;\!\:]*[\w@~%$£µ&i#\-+=_\/\?])*)/iu', '\\1www.\\2', '\\1'); MiniWiki::Markup('/(?:mailto:)?([a-z0-9.\-+_]+@([\-.+_]?[a-z0-9])+)/i', '\\0', '<\\0>'); MiniWiki::Markup('/\[\[\s*<(?:a href=")?([^">]*?)(?:">.*?<\/a)?>\s*\|([^\]]+)\]\]/i', '\\2', '\\2 <\\1>', "[[http://www.example.com|Mon site web]]\n\nhttp://www.example.com\n\ntest@example.com"); // paragraphs and empty lines MiniWiki::Markup("/\n\n/", '

', "\n\n", "paragraphe1\n\nparagraphe2"); MiniWiki::Markup("/\n/", ' ', "\n"); MiniWiki::Markup("/^.*<\/p>.*

.*$/s", "

$0

", "$0"); // french typo rules, unbreakable spaces MiniWiki::Markup("/ +([!?:;])/", " $1", "$0"); } public static function WikiToHTML($wiki, $title = false) { if (!$title) { $oldrule12 = MiniWiki::$replacementHTML[MiniWiki::$title_index]; MiniWiki::$replacementHTML[MiniWiki::$title_index] = "'$0'"; } $html = preg_replace(MiniWiki::$patternsWiki, MiniWiki::$replacementHTML, htmlentities(trim($wiki), ENT_COMPAT, 'UTF-8')); if (!$title) { MiniWiki::$replacementHTML[MiniWiki::$title_index] = $oldrule12; } return $html; } private static function justify($text, $n) { $arr = explode("\n", wordwrap($text, $n)); $arr = array_map('trim', $arr); $res = ''; foreach ($arr as $key => $line) { $nxl = isset($arr[$key+1]) ? trim($arr[$key+1]) : ''; $nxl_split = preg_split('! +!u', $nxl); $nxw_len = count($nxl_split) ? mb_strlen($nxl_split[0]) : 0; $line = trim($line); if (mb_strlen($line)+1+$nxw_len < $n) { $res .= "$line\n"; continue; } if (preg_match('![.:;]$!u',$line)) { $res .= "$line\n"; continue; } $tmp = preg_split('! +!u', trim($line)); $words = count($tmp); if ($words <= 1) { $res .= "$line\n"; continue; } $len = array_sum(array_map('mb_strlen', $tmp)); $empty = $n - $len; $sw = floatval($empty) / floatval($words-1); $cur = 0; $l = ''; foreach ($tmp as $word) { $l .= $word; $cur += $sw + strlen($word); // Use strlen here instead of mb_strlen because it is used by str_pad // which is not multibyte compatible $l = str_pad($l, intval($cur + 0.5)); } $res .= trim($l)."\n"; } return trim($res); } public static function WikiToText($wiki, $just=false, $indent=0, $width=68, $title=false) { if (!$title) { $oldrule12 = MiniWiki::$replacementHTML[MiniWiki::$title_index]; MiniWiki::$replacementHTML[MiniWiki::$title_index] = "'$0'"; } //$text = trim($wiki); //foreach (MiniWiki::$patternsWiki as $key=>$pattern) { // echo $key . " - " . $pattern . "\n"; // $text = preg_replace($pattern, MiniWiki::$replacementText[$key], $text); //} $text = preg_replace(MiniWiki::$patternsWiki, MiniWiki::$replacementText, trim($wiki)); if (!$title) { MiniWiki::$replacementHTML[MiniWiki::$title_index] = $oldrule12; } $text = $just ? MiniWiki::justify($text, $width - $indent) : wordwrap($text, $width - $indent); if($indent) { $ind = str_pad('',$indent); $text = $ind.str_replace("\n","\n$ind",$text); } return $text; } static public function help($with_title = false) { if (!$with_title) { $info12 = MiniWiki::$info[MiniWiki::$title_index]; unset(MiniWiki::$info[MiniWiki::$title_index]); } $res = array(); foreach (MiniWiki::$info as $value) { $res[$value] = MiniWiki::wikiToHtml($value, true); } if (!$with_title) { MiniWiki::$info[MiniWiki::$title_index] = $info12; } return $res; } } MiniWiki::init(); // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: ?>