mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
lines that start with inline html should not get parsed as block-level markup, should resolve #54 and #57
This commit is contained in:
parent
fee5b71998
commit
654dd74074
@ -149,12 +149,12 @@ class Parsedown
|
||||
|
||||
if ( ! isset($element['closed']))
|
||||
{
|
||||
if (preg_match('{<'.$element['root '].'>$}', $line)) # opening tag
|
||||
if (strpos($line, $element['start']) !== false) # opening tag
|
||||
{
|
||||
$element['depth']++;
|
||||
}
|
||||
|
||||
if (preg_match('{</'.$element['root '].'>$}', $line)) # closing tag
|
||||
if (strpos($line, $element['end']) !== false) # closing tag
|
||||
{
|
||||
$element['depth'] > 0
|
||||
? $element['depth']--
|
||||
@ -358,34 +358,70 @@ class Parsedown
|
||||
{
|
||||
case '<':
|
||||
|
||||
# self-closing tag
|
||||
$position = strpos($deindented_line, '>');
|
||||
|
||||
if (preg_match('{^<.+?/>$}', $deindented_line))
|
||||
if ($position > 1) # tag
|
||||
{
|
||||
$elements []= $element;
|
||||
$name = substr($deindented_line, 1, $position - 1);
|
||||
$name = rtrim($name);
|
||||
|
||||
$element = array(
|
||||
'type' => 'self-closing tag',
|
||||
'text' => $deindented_line,
|
||||
if (substr($name, -1) === '/')
|
||||
{
|
||||
$self_closing = true;
|
||||
|
||||
$name = substr($name, 0, -1);
|
||||
}
|
||||
|
||||
$position = strpos($name, ' ');
|
||||
|
||||
if ($position)
|
||||
{
|
||||
$name = substr($name, 0, $position);
|
||||
}
|
||||
|
||||
if ( ! ctype_alpha($name))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
$inline_tags = array(
|
||||
'a', 'abbr', 'acronym', 'b', 'bdo', 'big', 'br', 'button',
|
||||
'cite', 'code', 'dfn', 'em', 'i', 'img', 'input', 'kbd',
|
||||
'label', 'map', 'object', 'q', 'samp', 'script', 'select', 'small',
|
||||
'span', 'strong', 'sub', 'sup', 'textarea', 'tt', 'var',
|
||||
);
|
||||
|
||||
continue 2;
|
||||
}
|
||||
if (in_array($name, $inline_tags))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
# opening tag
|
||||
|
||||
if (preg_match('{^<(\w+)(?:[ ].*?)?>}', $deindented_line, $matches))
|
||||
{
|
||||
$elements []= $element;
|
||||
|
||||
if (isset($self_closing))
|
||||
{
|
||||
$element = array(
|
||||
'type' => 'self-closing tag',
|
||||
'text' => $deindented_line,
|
||||
);
|
||||
|
||||
unset($self_closing);
|
||||
|
||||
continue 2;
|
||||
}
|
||||
|
||||
$element = array(
|
||||
'type' => 'block-level markup',
|
||||
'text' => $deindented_line,
|
||||
'root ' => strtolower($matches[1]),
|
||||
'start' => '<'.$name.'>',
|
||||
'end' => '</'.$name.'>',
|
||||
'depth' => 0,
|
||||
);
|
||||
|
||||
preg_match('{</'.$matches[1].'>\s*$}', $deindented_line) and $element['closed'] = true;
|
||||
if (strpos($deindented_line, $element['end']))
|
||||
{
|
||||
$element['closed'] = true;
|
||||
}
|
||||
|
||||
continue 2;
|
||||
}
|
||||
@ -638,7 +674,7 @@ class Parsedown
|
||||
|
||||
case 'block-level markup':
|
||||
|
||||
$markup .= $this->parse_span_elements($element['text'])."\n";
|
||||
$markup .= $element['text']."\n";
|
||||
|
||||
break;
|
||||
|
||||
|
@ -1,9 +1,5 @@
|
||||
<div>content</div>
|
||||
<hr style="background: #eaa;" />
|
||||
<p>nested elements:</p>
|
||||
<div>_content_</div>
|
||||
<p>sparse:</p>
|
||||
<div>
|
||||
parent
|
||||
<div>
|
||||
child
|
||||
</div>
|
||||
_content_
|
||||
</div>
|
@ -1,12 +1,7 @@
|
||||
<div>content</div>
|
||||
<div>_content_</div>
|
||||
|
||||
<hr style="background: #eaa;" />
|
||||
|
||||
nested elements:
|
||||
sparse:
|
||||
|
||||
<div>
|
||||
parent
|
||||
<div>
|
||||
child
|
||||
</div>
|
||||
_content_
|
||||
</div>
|
10
tests/data/nested_block-level_html.html
Normal file
10
tests/data/nested_block-level_html.html
Normal file
@ -0,0 +1,10 @@
|
||||
<div>
|
||||
_parent_
|
||||
<div>
|
||||
_child_
|
||||
</div>
|
||||
<pre>
|
||||
_adopted child_
|
||||
</pre>
|
||||
</div>
|
||||
<p><em>outside</em></p>
|
11
tests/data/nested_block-level_html.md
Normal file
11
tests/data/nested_block-level_html.md
Normal file
@ -0,0 +1,11 @@
|
||||
<div>
|
||||
_parent_
|
||||
<div>
|
||||
_child_
|
||||
</div>
|
||||
<pre>
|
||||
_adopted child_
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
_outside_
|
4
tests/data/self-closing_block-level_html.html
Normal file
4
tests/data/self-closing_block-level_html.html
Normal file
@ -0,0 +1,4 @@
|
||||
<hr />
|
||||
<p>attributes:</p>
|
||||
<hr style="background: #9bd;" />
|
||||
<p>...</p>
|
7
tests/data/self-closing_block-level_html.md
Normal file
7
tests/data/self-closing_block-level_html.md
Normal file
@ -0,0 +1,7 @@
|
||||
<hr />
|
||||
|
||||
attributes:
|
||||
|
||||
<hr style="background: #9bd;" />
|
||||
|
||||
...
|
@ -1,3 +1,4 @@
|
||||
<p>an <b>important</b> <a href=''>link</a></p>
|
||||
<p>broken<br/>
|
||||
line</p>
|
||||
line</p>
|
||||
<p><b>inline tag</b> at the beginning</p>
|
@ -1,4 +1,6 @@
|
||||
an <b>important</b> <a href=''>link</a>
|
||||
|
||||
broken<br/>
|
||||
line
|
||||
line
|
||||
|
||||
<b>inline tag</b> at the beginning
|
Loading…
Reference in New Issue
Block a user