check the validity of heading

This commit is contained in:
Won-Kyu Park 2014-02-10 22:42:00 +09:00
parent d29ff18299
commit d3713588ae

View File

@ -277,18 +277,31 @@ class Parsedown
if (isset($line[1])) if (isset($line[1]))
{ {
$blocks []= $block;
$level = 1; $level = 1;
while (isset($line[$level]) and $line[$level] === '#') while (isset($line[$level]) and $level < 7 and $line[$level] === '#')
{ {
$level++; $level++;
} }
# check heading level
if ($level == 7)
{
break;
}
$heading = trim($line, '# ');
# check heading text
if ( ! isset($heading[0]))
{
break;
}
$blocks []= $block;
$block = array( $block = array(
'type' => 'heading', 'type' => 'heading',
'text' => trim($line, '# '), 'text' => $heading,
'level' => $level, 'level' => $level,
); );