Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added tests for consistency when a markdown follows a markup without blank line #514

Merged
merged 9 commits into from
Mar 25, 2018
55 changes: 2 additions & 53 deletions Parsedown.php
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ protected function blockMarkup($Line)
return;
}

if (preg_match('/^<(\w[\w-]*)(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*(\/)?>/', $Line['text'], $matches))
if (preg_match('/^<[\/]?+(\w*)(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*(\/)?>/', $Line['text'], $matches))
{
$element = strtolower($matches[1]);

Expand All @@ -734,71 +734,20 @@ protected function blockMarkup($Line)

$Block = array(
'name' => $matches[1],
'depth' => 0,
'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;
}
}

protected function blockMarkupContinue($Line, array $Block)
{
if (isset($Block['closed']))
if (isset($Block['closed']) or isset($Block['interrupted']))
{
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'];

return $Block;
Expand Down
3 changes: 2 additions & 1 deletion test/ParsedownTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ final function __construct($name = null, array $data = array(), $dataName = '')
parent::__construct($name, $data, $dataName);
}

private $dirs, $Parsedown;
private $dirs;
protected $Parsedown;

/**
* @return array
Expand Down
3 changes: 3 additions & 0 deletions test/data/markup_consecutive_one.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div>Markup</div>
_No markdown_ without blank line for **strict** compliance with CommonMark.
<p><strong>Markdown</strong></p>
4 changes: 4 additions & 0 deletions test/data/markup_consecutive_one.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div>Markup</div>
_No markdown_ without blank line for **strict** compliance with CommonMark.

**Markdown**
4 changes: 4 additions & 0 deletions test/data/markup_consecutive_one_line.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div>One markup on
two lines</div>
_No markdown_
<p><strong>Markdown</strong></p>
5 changes: 5 additions & 0 deletions test/data/markup_consecutive_one_line.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div>One markup on
two lines</div>
_No markdown_

**Markdown**
3 changes: 3 additions & 0 deletions test/data/markup_consecutive_one_stripped.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div><p>Stripped markup</p></div>
_No markdown_
<p><strong>Markdown</strong></p>
4 changes: 4 additions & 0 deletions test/data/markup_consecutive_one_stripped.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div><p>Stripped markup</p></div>
_No markdown_

**Markdown**
3 changes: 3 additions & 0 deletions test/data/markup_consecutive_two.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div>First markup</div><p>and second markup on the same line.</p>
_No markdown_
<p><strong>Markdown</strong></p>
4 changes: 4 additions & 0 deletions test/data/markup_consecutive_two.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div>First markup</div><p>and second markup on the same line.</p>
_No markdown_

**Markdown**
4 changes: 4 additions & 0 deletions test/data/markup_consecutive_two_lines.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div>First markup</div><p>and partial markup
on two lines.</p>
_No markdown_
<p><strong>Markdown</strong></p>
5 changes: 5 additions & 0 deletions test/data/markup_consecutive_two_lines.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div>First markup</div><p>and partial markup
on two lines.</p>
_No markdown_

**Markdown**
4 changes: 4 additions & 0 deletions test/data/markup_consecutive_two_stripped.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div><p>Stripped markup
on two lines</p></div>
_No markdown_
<p><strong>Markdown</strong></p>
5 changes: 5 additions & 0 deletions test/data/markup_consecutive_two_stripped.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div><p>Stripped markup
on two lines</p></div>
_No markdown_

**Markdown**
6 changes: 6 additions & 0 deletions test/data/self-closing_html.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
<hr>

paragraph
<hr/>

paragraph
<hr />

paragraph
<hr class="foo" id="bar" />

paragraph
<hr class="foo" id="bar"/>

paragraph
<hr class="foo" id="bar" >

paragraph
8 changes: 3 additions & 5 deletions test/data/sparse_html.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<div>
line 1

line 2
line 3

line 4
<p>line 2
line 3</p>
<p>line 4</p>
</div>