diff --git a/Parsedown.php b/Parsedown.php index a3efd7a..1dde17d 100755 --- a/Parsedown.php +++ b/Parsedown.php @@ -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; } # diff --git a/test/data/atx_heading.html b/test/data/atx_heading.html index 387e2ec..3b09c38 100644 --- a/test/data/atx_heading.html +++ b/test/data/atx_heading.html @@ -6,7 +6,8 @@
h6

####### not a heading

closed h1

-

#

+

+

# of levels

# of levels #

heading

\ No newline at end of file diff --git a/test/data/atx_heading.md b/test/data/atx_heading.md index 3724c1f..50f991c 100644 --- a/test/data/atx_heading.md +++ b/test/data/atx_heading.md @@ -16,6 +16,8 @@ # +## + # # of levels # # of levels # #