(\\\\*))\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", "'
', "\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: ?>