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:
parent
cf6d23de55
commit
772c919b05
@ -513,42 +513,39 @@ class Parsedown
|
||||
|
||||
protected function blockHeader($Line)
|
||||
{
|
||||
if (isset($Line['text'][1]))
|
||||
$level = 1;
|
||||
|
||||
while (isset($Line['text'][$level]) and $Line['text'][$level] === '#')
|
||||
{
|
||||
$level = 1;
|
||||
|
||||
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;
|
||||
$level ++;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
#
|
||||
|
@ -6,7 +6,8 @@
|
||||
<h6>h6</h6>
|
||||
<p>####### not a heading</p>
|
||||
<h1>closed h1</h1>
|
||||
<p>#</p>
|
||||
<h1></h1>
|
||||
<h2></h2>
|
||||
<h1># of levels</h1>
|
||||
<h1># of levels #</h1>
|
||||
<h1>heading</h1>
|
@ -16,6 +16,8 @@
|
||||
|
||||
#
|
||||
|
||||
##
|
||||
|
||||
# # of levels
|
||||
|
||||
# # of levels # #
|
||||
|
Loading…
Reference in New Issue
Block a user