5 public static function renderHTML($text)
7 if (is_null($text) || !strlen($text)) return NULL;
9 $lines = preg_split('/\r?\n/', $text);
11 foreach ($lines as &$line) {
12 if (!strlen($line)) continue;
22 '/^(.+)\[\[(https?:\/\/[^\]\|]+)\|([^\]]+)\]\]/',
23 '/^(.+)\[\[([^\]\|]+)\|([^\]]+)\]\]/',
24 '/^(.+)\[\[(https?:\/\/([^\]\|]+))\]\]/',
25 '/^(.+)\[\[([^\]\|]+)\]\]/',
28 "/'''''([^\']+)'''''/",
39 '${1}<a href="${2}" target="_blank">${3}</a>',
40 '${1}<a href="http://${2}" target="_blank">${3}</a>',
41 '${1}<a href="${2}" target="_blank">${3}</a>',
42 '${1}<a href="http://${2}" target="_blank">${2}</a>',
45 '<em><strong>${1}</strong></em>',
46 '<strong>${1}</strong>',
52 for ($i=0; $i < count($lines); $i++) {
53 if (strpos($lines[$i], '<ul-li>') === 0) {
54 for ($j=$i+1; $j < count($lines) && strpos($lines[$j], '<ul-li>') !== false; $j++);
55 $lines[$i] = '<p><ul>' . $lines[$i];
56 $lines[$j-1] = $lines[$j-1] . '</ul></p>';
58 } elseif (strpos($lines[$i], '<ol-li>') === 0) {
59 for ($j=$i+1; $j < count($lines) && strpos($lines[$j], '<ol-li>') !== false; $j++);
60 $lines[$i] = '<p><ol>' . $lines[$i];
61 $lines[$j-1] = $lines[$j-1] . '</ol></p>';
63 } elseif (strlen($lines[$i]) && strpos($lines[$i], '<') !== 0) {
64 for ($j=$i+1; $j < count($lines) && (strlen($lines[$j]) && strpos($lines[$j], '<') !== 0); $j++);
65 $lines[$i] = '<p>' . $lines[$i];
66 $lines[$j-1] = $lines[$j-1] . '</p>';
71 foreach ($lines as &$line) {
72 if (!strlen($line)) continue;
74 $line = str_replace(['<ul-li>', '<ol-li>'], ['<li>', '<li>'], $line);
77 return implode('', $lines);