1
0
mirror of https://github.com/erusev/parsedown.git synced 2023-08-10 21:13:06 +03:00

improve CommonMark compliance

This commit is contained in:
Emanuil Rusev 2015-01-10 02:45:51 +02:00
parent 7d3af6bf83
commit 06135cd75a
3 changed files with 25 additions and 6 deletions

View File

@ -35,9 +35,6 @@ class Parsedown
$text = str_replace("\r\n", "\n", $text);
$text = str_replace("\r", "\n", $text);
# replace tabs with spaces
$text = str_replace("\t", ' ', $text);
# remove surrounding line breaks
$text = trim($text, "\n");
@ -145,6 +142,23 @@ class Parsedown
continue;
}
if (strpos($line, "\t") !== false)
{
$parts = explode("\t", $line);
$line = $parts[0];
unset($parts[0]);
foreach ($parts as $part)
{
$shortage = 4 - mb_strlen($line, 'utf-8') % 4;
$line .= str_repeat(' ', $shortage);
$line .= $part;
}
}
$indent = 0;
while (isset($line[$indent]) and $line[$indent] === ' ')
@ -471,6 +485,11 @@ class Parsedown
$level ++;
}
if ($level > 6 or $Line['text'][$level] !== ' ')
{
return;
}
$text = trim($Line['text'], '# ');
$Block = array(
@ -614,7 +633,7 @@ class Parsedown
protected function blockRule($Line)
{
if (preg_match('/^(['.$Line['text'][0].'])([ ]{0,2}\1){2,}[ ]*$/', $Line['text']))
if (preg_match('/^(['.$Line['text'][0].'])([ ]*\1){2,}[ ]*$/', $Line['text']))
{
$Block = array(
'element' => array(

View File

@ -4,6 +4,6 @@
<h4>h4</h4>
<h5>h5</h5>
<h6>h6</h6>
<h6>h6</h6>
<p>####### not a heading</p>
<h1>closed h1</h1>
<p>#</p>

View File

@ -10,7 +10,7 @@
###### h6
####### h6
####### not a heading
# closed h1 #