setext heading doesn't have to use regex

This commit is contained in:
Emanuil Rusev 2014-01-17 01:23:25 +02:00
parent da966b83f1
commit 98b17e3354
1 changed files with 25 additions and 17 deletions

View File

@ -316,27 +316,35 @@ class Parsedown
break;
case '-':
# setext heading (---)
if ($line[0] === '-' and $element['type'] === 'paragraph' and ! isset($element['interrupted']) and preg_match('/^[-]+[ ]*$/', $line))
{
$element['type'] = 'heading';
$element['level'] = 2;
continue 2;
}
break;
case '=':
# setext heading (===)
# setext heading
if ($line[0] === '=' and $element['type'] === 'paragraph' and ! isset($element['interrupted']) and preg_match('/^[=]+[ ]*$/', $line))
if ($element['type'] === 'paragraph' and isset($element['interrupted']) === false)
{
$element['type'] = 'heading';
$element['level'] = 1;
$is_heading = true;
$chopped_line = rtrim($line);
$i = 1;
while (isset($chopped_line[$i]))
{
if ($chopped_line[$i] !== $line[0])
{
$is_heading = false;
break;
}
$i++;
}
if ($is_heading)
{
$element['type'] = 'heading';
$element['level'] = $line[0] === '-' ? 2 : 1;
}
continue 2;
}