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:
commit
56cc41803a
@ -723,7 +723,7 @@ class Parsedown
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (preg_match('/^<(\w[\w-]*)(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*(\/)?>/', $Line['text'], $matches))
|
if (preg_match('/^<[\/]?+(\w*)(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*(\/)?>/', $Line['text'], $matches))
|
||||||
{
|
{
|
||||||
$element = strtolower($matches[1]);
|
$element = strtolower($matches[1]);
|
||||||
|
|
||||||
@ -734,71 +734,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;
|
||||||
|
@ -13,7 +13,8 @@ class ParsedownTest extends TestCase
|
|||||||
parent::__construct($name, $data, $dataName);
|
parent::__construct($name, $data, $dataName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private $dirs, $Parsedown;
|
private $dirs;
|
||||||
|
protected $Parsedown;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
|
3
test/data/markup_consecutive_one.html
Normal file
3
test/data/markup_consecutive_one.html
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<div>Markup</div>
|
||||||
|
_No markdown_ without blank line for **strict** compliance with CommonMark.
|
||||||
|
<p><strong>Markdown</strong></p>
|
4
test/data/markup_consecutive_one.md
Normal file
4
test/data/markup_consecutive_one.md
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<div>Markup</div>
|
||||||
|
_No markdown_ without blank line for **strict** compliance with CommonMark.
|
||||||
|
|
||||||
|
**Markdown**
|
4
test/data/markup_consecutive_one_line.html
Normal file
4
test/data/markup_consecutive_one_line.html
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<div>One markup on
|
||||||
|
two lines</div>
|
||||||
|
_No markdown_
|
||||||
|
<p><strong>Markdown</strong></p>
|
5
test/data/markup_consecutive_one_line.md
Normal file
5
test/data/markup_consecutive_one_line.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<div>One markup on
|
||||||
|
two lines</div>
|
||||||
|
_No markdown_
|
||||||
|
|
||||||
|
**Markdown**
|
3
test/data/markup_consecutive_one_stripped.html
Normal file
3
test/data/markup_consecutive_one_stripped.html
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<div><p>Stripped markup</p></div>
|
||||||
|
_No markdown_
|
||||||
|
<p><strong>Markdown</strong></p>
|
4
test/data/markup_consecutive_one_stripped.md
Normal file
4
test/data/markup_consecutive_one_stripped.md
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<div><p>Stripped markup</p></div>
|
||||||
|
_No markdown_
|
||||||
|
|
||||||
|
**Markdown**
|
3
test/data/markup_consecutive_two.html
Normal file
3
test/data/markup_consecutive_two.html
Normal 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>
|
4
test/data/markup_consecutive_two.md
Normal file
4
test/data/markup_consecutive_two.md
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<div>First markup</div><p>and second markup on the same line.</p>
|
||||||
|
_No markdown_
|
||||||
|
|
||||||
|
**Markdown**
|
4
test/data/markup_consecutive_two_lines.html
Normal file
4
test/data/markup_consecutive_two_lines.html
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<div>First markup</div><p>and partial markup
|
||||||
|
on two lines.</p>
|
||||||
|
_No markdown_
|
||||||
|
<p><strong>Markdown</strong></p>
|
5
test/data/markup_consecutive_two_lines.md
Normal file
5
test/data/markup_consecutive_two_lines.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<div>First markup</div><p>and partial markup
|
||||||
|
on two lines.</p>
|
||||||
|
_No markdown_
|
||||||
|
|
||||||
|
**Markdown**
|
4
test/data/markup_consecutive_two_stripped.html
Normal file
4
test/data/markup_consecutive_two_stripped.html
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<div><p>Stripped markup
|
||||||
|
on two lines</p></div>
|
||||||
|
_No markdown_
|
||||||
|
<p><strong>Markdown</strong></p>
|
5
test/data/markup_consecutive_two_stripped.md
Normal file
5
test/data/markup_consecutive_two_stripped.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<div><p>Stripped markup
|
||||||
|
on two lines</p></div>
|
||||||
|
_No markdown_
|
||||||
|
|
||||||
|
**Markdown**
|
@ -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
|
@ -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>
|
Loading…
Reference in New Issue
Block a user