From 54573d2e4869dbda764c0e4dc32a349a9ab56a72 Mon Sep 17 00:00:00 2001 From: Esteban <25874603+stbneb@users.noreply.github.com> Date: Wed, 12 Jul 2023 18:19:53 -0300 Subject: [PATCH] Fix #215: pre tags with attrs not being parsed (#238) --- src/Converter/PreformattedConverter.php | 4 +++- tests/HtmlConverterTest.php | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Converter/PreformattedConverter.php b/src/Converter/PreformattedConverter.php index 7d8ccc1..af6dd10 100644 --- a/src/Converter/PreformattedConverter.php +++ b/src/Converter/PreformattedConverter.php @@ -11,7 +11,9 @@ class PreformattedConverter implements ConverterInterface public function convert(ElementInterface $element): string { $preContent = \html_entity_decode($element->getChildrenAsString()); - $preContent = \str_replace(['
', '
'], '', $preContent); + $preContent = \preg_replace('/]*>/', '', $preContent); + \assert($preContent !== null); + $preContent = \str_replace('', '', $preContent); /* * Checking for the code tag. diff --git a/tests/HtmlConverterTest.php b/tests/HtmlConverterTest.php index 64b9086..4b71832 100644 --- a/tests/HtmlConverterTest.php +++ b/tests/HtmlConverterTest.php @@ -300,6 +300,7 @@ public function testPreformat(): void $this->assertHtmlGivesMarkdown("
\n\n\n
", "```\n\n\n\n```"); $this->assertHtmlGivesMarkdown("
\n
\n
", "```\n\n```\n\n```\n\n```"); $this->assertHtmlGivesMarkdown("
one\ntwo\r\nthree
\n

line

", "```\none\ntwo\nthree\n```\n\nline"); + $this->assertHtmlGivesMarkdown("
test with attributes
", "```\ntest with attributes\n```"); } public function testBlockquotes(): void