Skip to content

Commit

Permalink
Fix bug where empty atx headings would not be recognised (CommonMark)
Browse files Browse the repository at this point in the history
Fixes #595
  • Loading branch information
aidantwoods committed Apr 2, 2018
1 parent cf6d23d commit 772c919
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
55 changes: 26 additions & 29 deletions Parsedown.php
Original file line number Diff line number Diff line change
Expand Up @@ -513,42 +513,39 @@ protected function blockFencedCodeComplete($Block)

protected function blockHeader($Line)
{
if (isset($Line['text'][1]))
{
$level = 1;
$level = 1;

while (isset($Line['text'][$level]) and $Line['text'][$level] === '#')
{
$level ++;
}
while (isset($Line['text'][$level]) and $Line['text'][$level] === '#')
{
$level ++;
}

if ($level > 6)
{
return;
}
if ($level > 6)
{
return;
}

$text = trim($Line['text'], '#');
$text = trim($Line['text'], '#');

if ($this->strictMode and ( ! isset($text[0]) or $text[0] !== ' '))
{
return;
}
if ($this->strictMode and isset($text[0]) and $text[0] !== ' ')
{
return;
}

$text = trim($text, ' ');
$text = trim($text, ' ');

$Block = array(
'element' => array(
'name' => 'h' . min(6, $level),
'handler' => array(
'function' => 'lineElements',
'argument' => $text,
'destination' => 'elements',
)
),
);
$Block = array(
'element' => array(
'name' => 'h' . min(6, $level),
'handler' => array(
'function' => 'lineElements',
'argument' => $text,
'destination' => 'elements',
)
),
);

return $Block;
}
return $Block;
}

#
Expand Down
3 changes: 2 additions & 1 deletion test/data/atx_heading.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ <h5>h5</h5>
<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>
2 changes: 2 additions & 0 deletions test/data/atx_heading.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

#

##

# # of levels

# # of levels # #
Expand Down

0 comments on commit 772c919

Please sign in to comment.