Skip to content

Commit

Permalink
Added tests to check issue erusev#44.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel-KM committed Jun 18, 2017
1 parent 3edee6a commit 8be5b5a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 12 deletions.
25 changes: 13 additions & 12 deletions ParsedownExtra.php
Original file line number Diff line number Diff line change
Expand Up @@ -1169,18 +1169,17 @@ protected function parseAttributeData($attributeString)

# ~

protected function processText($document, $element){
protected function processText($document, $element)
{
$nodeMarkup = $document->saveHTML($element);

$text = '';

if ($element instanceof DOMElement and !in_array($element->nodeName, $this->textLevelElements) and !in_array($element->nodeName, $this->voidElements)){
if( $element->hasChildNodes() ){
$text = $this->processTags($nodeMarkup);
}else{
$text = $nodeMarkup;
}
}else{
if ($element instanceof DOMElement
&& !in_array($element->nodeName, $this->textLevelElements)
&& !in_array($element->nodeName, $this->voidElements)
&& $element->hasChildNodes()
) {
$text = $this->processTags($nodeMarkup);
} else {
$text = $nodeMarkup;
}
return $text;
Expand Down Expand Up @@ -1223,7 +1222,7 @@ protected function processTag($document, $element) # recursive

$elementText = '';

if ($element instanceof DOMElement and $element->getAttribute('markdown') === '1')
if ($element instanceof DOMElement && $element->getAttribute('markdown') === '1')
{
if( $element->hasChildNodes() ){
foreach ($element->childNodes as $Node){
Expand All @@ -1242,7 +1241,9 @@ protected function processTag($document, $element) # recursive
foreach ($element->childNodes as $Node){
$elementText .= $this->processText($document, $Node);
}
}else{
} elseif ($element instanceof DOMElement){
$elementText = $document->saveHTML($element);
} else {
$elementText = $this->processText($document, $element);
}

Expand Down
34 changes: 34 additions & 0 deletions test/ParsedownExtraTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,38 @@ public function test_footnote_prefix()

$this->assertEquals( $expectedOutput, $parsedown->text( $markdownInput ) );
}

public function testMultipleHtmlMarkupInline()
{
// @url https://github.com/erusev/parsedown-extra/issues/44#issuecomment-80815953
$input = <<<EOF
<div>1</div><p>2</p>
The p tag (and contents), along with this line are eaten.
EOF;
$expectedMarkup = <<<EOF
<div>1</div><p>2</p>
<p>The p tag (and contents), along with this line are eaten.</p>
EOF;
$actualMarkup = (new ParsedownExtra())->text($input);

$this->assertEquals($expectedMarkup, $actualMarkup);
}

public function testInlineIframe()
{
// @url https://github.com/erusev/parsedown-extra/issues/44#issuecomment-106090346
$expectedMarkup = '<iframe />';
$actualMarkup = (new ParsedownExtra())->text($expectedMarkup);

$this->assertEquals($expectedMarkup, $actualMarkup);
}

public function testStripping()
{
// @url https://github.com/erusev/parsedown-extra/issues/44#issuecomment-159655861
$expectedMarkup = '<p><strong>Contact Method:</strong> email</p><p>Test</p><p><em>Some italic text.</em></p>';
$actualMarkup = (new ParsedownExtra())->text($expectedMarkup);

$this->assertEquals($expectedMarkup, $actualMarkup);
}
}

0 comments on commit 8be5b5a

Please sign in to comment.