Skip to content

Commit 54573d2

Browse files
authored
Fix #215: pre tags with attrs not being parsed (#238)
1 parent e72ed92 commit 54573d2

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/Converter/PreformattedConverter.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ class PreformattedConverter implements ConverterInterface
1111
public function convert(ElementInterface $element): string
1212
{
1313
$preContent = \html_entity_decode($element->getChildrenAsString());
14-
$preContent = \str_replace(['<pre>', '</pre>'], '', $preContent);
14+
$preContent = \preg_replace('/<pre\b[^>]*>/', '', $preContent);
15+
\assert($preContent !== null);
16+
$preContent = \str_replace('</pre>', '', $preContent);
1517

1618
/*
1719
* Checking for the code tag.

tests/HtmlConverterTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ public function testPreformat(): void
300300
$this->assertHtmlGivesMarkdown("<pre>\n\n\n</pre>", "```\n\n\n\n```");
301301
$this->assertHtmlGivesMarkdown("<pre>\n</pre><pre>\n</pre>", "```\n\n```\n\n```\n\n```");
302302
$this->assertHtmlGivesMarkdown("<pre>one\ntwo\r\nthree</pre>\n<p>line</p>", "```\none\ntwo\nthree\n```\n\nline");
303+
$this->assertHtmlGivesMarkdown("<pre class='some-class'>test with attributes</pre>", "```\ntest with attributes\n```");
303304
}
304305

305306
public function testBlockquotes(): void

0 commit comments

Comments
 (0)