FIX headers

This commit is contained in:
Krivchikov Dmitry 2015-09-29 23:24:34 +03:00
parent dc7d394e07
commit a378998313
1 changed files with 9 additions and 11 deletions

View File

@ -17,19 +17,17 @@ class Markdown
static private function replaceHeaders($string) static private function replaceHeaders($string)
{ {
for ($index = 3; $index > 0; $index--) { $pr = '(^#{1} (.{1,}))';
$rep = '<h2>$1</h2>';
$string = preg_replace($pr, $rep, $string);
$pr = '/(^#{' . $index . '} .{1,})/m'; $pr = '(^#{2} (.{1,}))';
$rep = '<h3>$1</h3>';
$string = preg_replace($pr, $rep, $string);
preg_match_all($pr, $string, $headers); $pr = '(^#{3} (.{1,}))';
$rep = '<h4>$1</h4>';
if (isset($headers[0][0])) { $string = preg_replace($pr, $rep, $string);
foreach ($headers[0] as $header) {
$hI = $index+1;
$string = str_replace($header, "<h$hI>" . mb_substr($header, $index + 1, NULL, 'UTF-8') . "</h$hI>", $string);
}
}
}
return $string; return $string;
} }