+ MiniWiki::Markup("/^.*<\/p>.*<p>.*$/s", "<p>$0</p>", "$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);