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

Merge pull request #514 from Daniel-KM/fix/consistency_follow

Added tests for consistency when a markdown follows a markup without blank line
This commit is contained in:
Aidan Woods 2018-03-25 19:53:21 +01:00 committed by GitHub
commit 56cc41803a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 61 additions and 59 deletions

View File

@ -723,7 +723,7 @@ class Parsedown
return;
}
if (preg_match('/^<(\w[\w-]*)(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*(\/)?>/', $Line['text'], $matches))
if (preg_match('/^<[\/]?+(\w*)(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*(\/)?>/', $Line['text'], $matches))
{
$element = strtolower($matches[1]);
@ -734,71 +734,20 @@ class Parsedown
$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;

View File

@ -13,7 +13,8 @@ class ParsedownTest extends TestCase
parent::__construct($name, $data, $dataName);
}
private $dirs, $Parsedown;
private $dirs;
protected $Parsedown;
/**
* @return array

View File

@ -0,0 +1,3 @@
<div>Markup</div>
_No markdown_ without blank line for **strict** compliance with CommonMark.
<p><strong>Markdown</strong></p>

View File

@ -0,0 +1,4 @@
<div>Markup</div>
_No markdown_ without blank line for **strict** compliance with CommonMark.
**Markdown**

View File

@ -0,0 +1,4 @@
<div>One markup on
two lines</div>
_No markdown_
<p><strong>Markdown</strong></p>

View File

@ -0,0 +1,5 @@
<div>One markup on
two lines</div>
_No markdown_
**Markdown**

View File

@ -0,0 +1,3 @@
<div><p>Stripped markup</p></div>
_No markdown_
<p><strong>Markdown</strong></p>

View File

@ -0,0 +1,4 @@
<div><p>Stripped markup</p></div>
_No markdown_
**Markdown**

View File

@ -0,0 +1,3 @@
<div>First markup</div><p>and second markup on the same line.</p>
_No markdown_
<p><strong>Markdown</strong></p>

View File

@ -0,0 +1,4 @@
<div>First markup</div><p>and second markup on the same line.</p>
_No markdown_
**Markdown**

View File

@ -0,0 +1,4 @@
<div>First markup</div><p>and partial markup
on two lines.</p>
_No markdown_
<p><strong>Markdown</strong></p>

View File

@ -0,0 +1,5 @@
<div>First markup</div><p>and partial markup
on two lines.</p>
_No markdown_
**Markdown**

View File

@ -0,0 +1,4 @@
<div><p>Stripped markup
on two lines</p></div>
_No markdown_
<p><strong>Markdown</strong></p>

View File

@ -0,0 +1,5 @@
<div><p>Stripped markup
on two lines</p></div>
_No markdown_
**Markdown**

View File

@ -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

View File

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