mirror of
https://github.com/erusev/parsedown.git
synced 2024-09-19 19:41:29 +02:00
improve CommonMark compliance
This commit is contained in:
parent
7d3af6bf83
commit
06135cd75a
@ -35,9 +35,6 @@ class Parsedown
|
|||||||
$text = str_replace("\r\n", "\n", $text);
|
$text = str_replace("\r\n", "\n", $text);
|
||||||
$text = str_replace("\r", "\n", $text);
|
$text = str_replace("\r", "\n", $text);
|
||||||
|
|
||||||
# replace tabs with spaces
|
|
||||||
$text = str_replace("\t", ' ', $text);
|
|
||||||
|
|
||||||
# remove surrounding line breaks
|
# remove surrounding line breaks
|
||||||
$text = trim($text, "\n");
|
$text = trim($text, "\n");
|
||||||
|
|
||||||
@ -145,6 +142,23 @@ class Parsedown
|
|||||||
continue;
|
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;
|
$indent = 0;
|
||||||
|
|
||||||
while (isset($line[$indent]) and $line[$indent] === ' ')
|
while (isset($line[$indent]) and $line[$indent] === ' ')
|
||||||
@ -471,6 +485,11 @@ class Parsedown
|
|||||||
$level ++;
|
$level ++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($level > 6 or $Line['text'][$level] !== ' ')
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$text = trim($Line['text'], '# ');
|
$text = trim($Line['text'], '# ');
|
||||||
|
|
||||||
$Block = array(
|
$Block = array(
|
||||||
@ -614,7 +633,7 @@ class Parsedown
|
|||||||
|
|
||||||
protected function blockRule($Line)
|
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(
|
$Block = array(
|
||||||
'element' => array(
|
'element' => array(
|
||||||
|
@ -4,6 +4,6 @@
|
|||||||
<h4>h4</h4>
|
<h4>h4</h4>
|
||||||
<h5>h5</h5>
|
<h5>h5</h5>
|
||||||
<h6>h6</h6>
|
<h6>h6</h6>
|
||||||
<h6>h6</h6>
|
<p>####### not a heading</p>
|
||||||
<h1>closed h1</h1>
|
<h1>closed h1</h1>
|
||||||
<p>#</p>
|
<p>#</p>
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
###### h6
|
###### h6
|
||||||
|
|
||||||
####### h6
|
####### not a heading
|
||||||
|
|
||||||
# closed h1 #
|
# closed h1 #
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user