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

Fix bug where empty atx headings would not be recognised (CommonMark)

Fixes #595
This commit is contained in:
Aidan Woods 2018-04-02 17:09:54 +01:00
parent cf6d23de55
commit 772c919b05
No known key found for this signature in database
GPG Key ID: 9A6A8EFAA512BBB9
3 changed files with 35 additions and 35 deletions

View File

@ -513,42 +513,39 @@ class Parsedown
protected function blockHeader($Line) protected function blockHeader($Line)
{ {
if (isset($Line['text'][1])) $level = 1;
while (isset($Line['text'][$level]) and $Line['text'][$level] === '#')
{ {
$level = 1; $level ++;
while (isset($Line['text'][$level]) and $Line['text'][$level] === '#')
{
$level ++;
}
if ($level > 6)
{
return;
}
$text = trim($Line['text'], '#');
if ($this->strictMode and ( ! isset($text[0]) or $text[0] !== ' '))
{
return;
}
$text = trim($text, ' ');
$Block = array(
'element' => array(
'name' => 'h' . min(6, $level),
'handler' => array(
'function' => 'lineElements',
'argument' => $text,
'destination' => 'elements',
)
),
);
return $Block;
} }
if ($level > 6)
{
return;
}
$text = trim($Line['text'], '#');
if ($this->strictMode and isset($text[0]) and $text[0] !== ' ')
{
return;
}
$text = trim($text, ' ');
$Block = array(
'element' => array(
'name' => 'h' . min(6, $level),
'handler' => array(
'function' => 'lineElements',
'argument' => $text,
'destination' => 'elements',
)
),
);
return $Block;
} }
# #

View File

@ -6,7 +6,8 @@
<h6>h6</h6> <h6>h6</h6>
<p>####### not a heading</p> <p>####### not a heading</p>
<h1>closed h1</h1> <h1>closed h1</h1>
<p>#</p> <h1></h1>
<h2></h2>
<h1># of levels</h1> <h1># of levels</h1>
<h1># of levels #</h1> <h1># of levels #</h1>
<h1>heading</h1> <h1>heading</h1>

View File

@ -16,6 +16,8 @@
# #
##
# # of levels # # of levels
# # of levels # # # # of levels # #