1
0
mirror of https://github.com/erusev/parsedown.git synced 2023-08-10 21:13:06 +03:00

Merge branch 'aidantwoods-htmlblocks' into fix/consistency_follow

This commit is contained in:
Daniel Berthereau 2017-06-23 00:00:00 +02:00
commit c05ef0c12a
3 changed files with 13 additions and 60 deletions

View File

@ -683,7 +683,7 @@ class Parsedown
return; return;
} }
if (preg_match('/^<(\w*)(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*(\/)?>/', $Line['text'], $matches)) if (preg_match('/^<[\/]?+(\w*)(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*(\/)?>/', $Line['text'], $matches))
{ {
$element = strtolower($matches[1]); $element = strtolower($matches[1]);
@ -694,71 +694,20 @@ class Parsedown
$Block = array( $Block = array(
'name' => $matches[1], 'name' => $matches[1],
'depth' => 0,
'markup' => $Line['text'], 'markup' => $Line['text'],
); );
$length = strlen($matches[0]);
$remainder = substr($Line['text'], $length);
if (trim($remainder) === '')
{
if (isset($matches[2]) or in_array($matches[1], $this->voidElements))
{
$Block['closed'] = true;
$Block['void'] = true;
}
}
else
{
if (isset($matches[2]) or in_array($matches[1], $this->voidElements))
{
return;
}
if (preg_match('/<\/'.$matches[1].'>[ ]*$/i', $remainder))
{
$Block['closed'] = true;
}
}
return $Block; return $Block;
} }
} }
protected function blockMarkupContinue($Line, array $Block) protected function blockMarkupContinue($Line, array $Block)
{ {
if (isset($Block['closed'])) if (isset($Block['closed']) or isset($Block['interrupted']))
{ {
return; return;
} }
if (preg_match('/^<'.$Block['name'].'(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*>/i', $Line['text'])) # open
{
$Block['depth'] ++;
}
if (preg_match('/(.*?)<\/'.$Block['name'].'>[ ]*$/i', $Line['text'], $matches)) # close
{
if ($Block['depth'] > 0)
{
$Block['depth'] --;
}
else
{
$Block['closed'] = true;
}
}
if (isset($Block['interrupted']))
{
$Block['markup'] .= "\n";
unset($Block['interrupted']);
}
$Block['markup'] .= "\n".$Line['body']; $Block['markup'] .= "\n".$Line['body'];
return $Block; return $Block;

View File

@ -1,12 +1,18 @@
<hr> <hr>
paragraph paragraph
<hr/> <hr/>
paragraph paragraph
<hr /> <hr />
paragraph paragraph
<hr class="foo" id="bar" /> <hr class="foo" id="bar" />
paragraph paragraph
<hr class="foo" id="bar"/> <hr class="foo" id="bar"/>
paragraph paragraph
<hr class="foo" id="bar" > <hr class="foo" id="bar" >
paragraph paragraph

View File

@ -1,8 +1,6 @@
<div> <div>
line 1 line 1
<p>line 2
line 2 line 3</p>
line 3 <p>line 4</p>
line 4
</div> </div>