refactor parsing of html

This commit is contained in:
Emanuil Rusev 2014-01-27 00:10:24 +02:00
parent 0f090e1a6e
commit 6069fdac81
1 changed files with 26 additions and 16 deletions

View File

@ -334,23 +334,28 @@ class Parsedown
$position = strpos($deindented_line, '>'); $position = strpos($deindented_line, '>');
if ($position > 1) # tag if ($position > 1)
{ {
$name = substr($deindented_line, 1, $position - 1); $substring = substr($deindented_line, 1, $position - 1);
$name = chop($name);
if (substr($name, -1) === '/') $substring = chop($substring);
if (substr($substring, -1) === '/')
{ {
$self_closing = true; $is_self_closing = true;
$name = substr($name, 0, -1); $substring = substr($substring, 0, -1);
} }
$position = strpos($name, ' '); $position = strpos($substring, ' ');
if ($position) if ($position)
{ {
$name = substr($name, 0, $position); $name = substr($substring, 0, $position);
}
else
{
$name = $substring;
} }
if ( ! ctype_alpha($name)) if ( ! ctype_alpha($name))
@ -358,21 +363,21 @@ class Parsedown
break; break;
} }
if (in_array($name, $this->inline_tags)) if (in_array($name, self::$text_level_elements))
{ {
break; break;
} }
$blocks []= $block; $blocks []= $block;
if (isset($self_closing)) if (isset($is_self_closing))
{ {
$block = array( $block = array(
'type' => 'self-closing tag', 'type' => 'self-closing tag',
'text' => $deindented_line, 'text' => $deindented_line,
); );
unset($self_closing); unset($is_self_closing);
continue 2; continue 2;
} }
@ -1058,11 +1063,16 @@ class Parsedown
# Read-only # Read-only
# #
private $inline_tags = array( private static $text_level_elements = array(
'a', 'abbr', 'acronym', 'b', 'bdo', 'big', 'br', 'button', 'a', 'br', 'bdo', 'abbr', 'blink', 'nextid', 'acronym', 'basefont',
'cite', 'code', 'dfn', 'em', 'i', 'img', 'input', 'kbd', 'b', 'em', 'big', 'cite', 'small', 'spacer', 'listing',
'label', 'map', 'object', 'q', 'samp', 'script', 'select', 'small', 'i', 'rp', 'sub', 'code', 'strike', 'marquee',
'span', 'strong', 'sub', 'sup', 'textarea', 'tt', 'var', 'q', 'rt', 'sup', 'font', 'strong',
's', 'tt', 'var', 'mark',
'u', 'xm', 'wbr', 'nobr',
'ruby',
'span',
'time',
); );
private $special_characters = array('\\', '`', '*', '_', '{', '}', '[', ']', '(', ')', '>', '#', '+', '-', '.', '!'); private $special_characters = array('\\', '`', '*', '_', '{', '}', '[', ']', '(', ')', '>', '#', '+', '-', '.', '!');