From 6d8aabab2347feabdd804b609dcd4513f09f78d4 Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 11 Feb 2022 09:21:19 +0000 Subject: composer libs minor version updates --- .../league/html-to-markdown/src/HtmlConverter.php | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'vendor/league/html-to-markdown/src/HtmlConverter.php') diff --git a/vendor/league/html-to-markdown/src/HtmlConverter.php b/vendor/league/html-to-markdown/src/HtmlConverter.php index 7cd543b34..7162b256d 100644 --- a/vendor/league/html-to-markdown/src/HtmlConverter.php +++ b/vendor/league/html-to-markdown/src/HtmlConverter.php @@ -121,6 +121,8 @@ class HtmlConverter implements HtmlConverterInterface $document->loadHTML('' . $html); $document->encoding = 'UTF-8'; + $this->replaceMisplacedComments($document); + if ($this->getConfig()->getOption('suppress_errors')) { \libxml_clear_errors(); } @@ -128,6 +130,36 @@ class HtmlConverter implements HtmlConverterInterface return $document; } + /** + * Finds any comment nodes outside element and moves them into . + * + * @see https://github.com/thephpleague/html-to-markdown/issues/212 + * @see https://3v4l.org/7bC33 + */ + private function replaceMisplacedComments(\DOMDocument $document): void + { + // Find ny comment nodes at the root of the document. + $misplacedComments = (new \DOMXPath($document))->query('/comment()'); + if ($misplacedComments === false) { + return; + } + + $body = $document->getElementsByTagName('body')->item(0); + if ($body === null) { + return; + } + + // Loop over comment nodes in reverse so we put them inside in + // their original order. + for ($index = $misplacedComments->length - 1; $index >= 0; $index--) { + if ($body->firstChild === null) { + $body->insertBefore($misplacedComments[$index]); + } else { + $body->insertBefore($misplacedComments[$index], $body->firstChild); + } + } + } + /** * Convert Children * -- cgit v1.2.3