diff options
Diffstat (limited to 'vendor/league/html-to-markdown/src')
3 files changed, 34 insertions, 2 deletions
diff --git a/vendor/league/html-to-markdown/src/Converter/HorizontalRuleConverter.php b/vendor/league/html-to-markdown/src/Converter/HorizontalRuleConverter.php index ce280cc79..a2b1ac14a 100644 --- a/vendor/league/html-to-markdown/src/Converter/HorizontalRuleConverter.php +++ b/vendor/league/html-to-markdown/src/Converter/HorizontalRuleConverter.php @@ -10,7 +10,7 @@ class HorizontalRuleConverter implements ConverterInterface { public function convert(ElementInterface $element): string { - return "- - - - - -\n\n"; + return "---\n\n"; } /** diff --git a/vendor/league/html-to-markdown/src/Element.php b/vendor/league/html-to-markdown/src/Element.php index 5407f1ffb..0515b5995 100644 --- a/vendor/league/html-to-markdown/src/Element.php +++ b/vendor/league/html-to-markdown/src/Element.php @@ -63,7 +63,7 @@ class Element implements ElementInterface public function getValue(): string { - return $this->node->nodeValue; + return $this->node->nodeValue ?? ''; } public function hasParent(): bool 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('<?xml encoding="UTF-8">' . $html); $document->encoding = 'UTF-8'; + $this->replaceMisplacedComments($document); + if ($this->getConfig()->getOption('suppress_errors')) { \libxml_clear_errors(); } @@ -129,6 +131,36 @@ class HtmlConverter implements HtmlConverterInterface } /** + * Finds any comment nodes outside <html> element and moves them into <body>. + * + * @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 <body> 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 * * Recursive function to drill into the DOM and convert each node into Markdown from the inside out. |