diff options
author | Mario <mario@mariovavti.com> | 2023-11-25 17:12:28 +0100 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2023-11-25 17:12:28 +0100 |
commit | 0fd8e02a884a2b040dca62ab5d9674db5f6a070b (patch) | |
tree | 586ee43f32f6f14368c09026f21dcd3244ea24b6 /vendor/league/html-to-markdown/src | |
parent | 82e704ec5b107823c09f1387e9091adee53a4c2d (diff) | |
parent | 55c4bfb67009c598f25b1a8189604bfffa73dfbb (diff) | |
download | volse-hubzilla-8.8.tar.gz volse-hubzilla-8.8.tar.bz2 volse-hubzilla-8.8.zip |
Merge branch '8.8RC'8.8
Diffstat (limited to 'vendor/league/html-to-markdown/src')
7 files changed, 49 insertions, 12 deletions
diff --git a/vendor/league/html-to-markdown/src/Coerce.php b/vendor/league/html-to-markdown/src/Coerce.php new file mode 100644 index 000000000..4fb0450a0 --- /dev/null +++ b/vendor/league/html-to-markdown/src/Coerce.php @@ -0,0 +1,35 @@ +<?php + +declare(strict_types=1); + +namespace League\HTMLToMarkdown; + +/** + * @internal + */ +final class Coerce +{ + private function __construct() + { + } + + /** + * @param mixed $val + */ + public static function toString($val): string + { + switch (true) { + case \is_string($val): + return $val; + case \is_bool($val): + case \is_float($val): + case \is_int($val): + case $val === null: + return \strval($val); + case \is_object($val) && \method_exists($val, '__toString'): + return $val->__toString(); + default: + throw new \InvalidArgumentException('Cannot coerce this value to string'); + } + } +} diff --git a/vendor/league/html-to-markdown/src/Converter/LinkConverter.php b/vendor/league/html-to-markdown/src/Converter/LinkConverter.php index 25a3540fe..f0ba157f8 100644 --- a/vendor/league/html-to-markdown/src/Converter/LinkConverter.php +++ b/vendor/league/html-to-markdown/src/Converter/LinkConverter.php @@ -72,6 +72,6 @@ class LinkConverter implements ConverterInterface, ConfigurationAwareInterface private function shouldStrip(): bool { - return $this->config->getOption('strip_placeholder_links') ?? false; + return \boolval($this->config->getOption('strip_placeholder_links') ?? false); } } diff --git a/vendor/league/html-to-markdown/src/Converter/ListItemConverter.php b/vendor/league/html-to-markdown/src/Converter/ListItemConverter.php index 1521aad53..d71f601e1 100644 --- a/vendor/league/html-to-markdown/src/Converter/ListItemConverter.php +++ b/vendor/league/html-to-markdown/src/Converter/ListItemConverter.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace League\HTMLToMarkdown\Converter; +use League\HTMLToMarkdown\Coerce; use League\HTMLToMarkdown\Configuration; use League\HTMLToMarkdown\ConfigurationAwareInterface; use League\HTMLToMarkdown\ElementInterface; @@ -38,8 +39,8 @@ class ListItemConverter implements ConverterInterface, ConfigurationAwareInterfa } if ($listType === 'ul') { - $listItemStyle = $this->config->getOption('list_item_style', '-'); - $listItemStyleAlternate = $this->config->getOption('list_item_style_alternate'); + $listItemStyle = Coerce::toString($this->config->getOption('list_item_style', '-')); + $listItemStyleAlternate = Coerce::toString($this->config->getOption('list_item_style_alternate', '')); if (! isset($this->listItemStyle)) { $this->listItemStyle = $listItemStyleAlternate ?: $listItemStyle; } diff --git a/vendor/league/html-to-markdown/src/Converter/PreformattedConverter.php b/vendor/league/html-to-markdown/src/Converter/PreformattedConverter.php index 7d8ccc132..af6dd1051 100644 --- a/vendor/league/html-to-markdown/src/Converter/PreformattedConverter.php +++ b/vendor/league/html-to-markdown/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(['<pre>', '</pre>'], '', $preContent); + $preContent = \preg_replace('/<pre\b[^>]*>/', '', $preContent); + \assert($preContent !== null); + $preContent = \str_replace('</pre>', '', $preContent); /* * Checking for the code tag. diff --git a/vendor/league/html-to-markdown/src/Converter/TableConverter.php b/vendor/league/html-to-markdown/src/Converter/TableConverter.php index 2e63e9a5b..91e718076 100644 --- a/vendor/league/html-to-markdown/src/Converter/TableConverter.php +++ b/vendor/league/html-to-markdown/src/Converter/TableConverter.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace League\HTMLToMarkdown\Converter; +use League\HTMLToMarkdown\Coerce; use League\HTMLToMarkdown\Configuration; use League\HTMLToMarkdown\ConfigurationAwareInterface; use League\HTMLToMarkdown\ElementInterface; @@ -89,7 +90,7 @@ class TableConverter implements ConverterInterface, PreConverterInterface, Confi } $value = \str_replace("\n", ' ', $value); - $value = \str_replace('|', $this->config->getOption('table_pipe_escape') ?? '\|', $value); + $value = \str_replace('|', Coerce::toString($this->config->getOption('table_pipe_escape') ?? '\|'), $value); return '| ' . \trim($value) . ' '; case 'thead': diff --git a/vendor/league/html-to-markdown/src/Element.php b/vendor/league/html-to-markdown/src/Element.php index 0515b5995..ef3ecfa9a 100644 --- a/vendor/league/html-to-markdown/src/Element.php +++ b/vendor/league/html-to-markdown/src/Element.php @@ -98,6 +98,8 @@ class Element implements ElementInterface { $ret = []; foreach ($this->node->childNodes as $node) { + /** @psalm-suppress RedundantCondition */ + \assert($node instanceof \DOMNode); $ret[] = new self($node); } @@ -116,7 +118,7 @@ class Element implements ElementInterface return $this->nextCached; } - private function getNextNode(\DomNode $node, bool $checkChildren = true): ?\DomNode + private function getNextNode(\DOMNode $node, bool $checkChildren = true): ?\DOMNode { if ($checkChildren && $node->firstChild) { return $node->firstChild; @@ -142,11 +144,7 @@ class Element implements ElementInterface $tagNames = [$tagNames]; } - for ($p = $this->node->parentNode; $p !== false; $p = $p->parentNode) { - if ($p === null) { - return false; - } - + for ($p = $this->node->parentNode; $p !== null; $p = $p->parentNode) { if (\in_array($p->nodeName, $tagNames, true)) { return true; } diff --git a/vendor/league/html-to-markdown/src/HtmlConverter.php b/vendor/league/html-to-markdown/src/HtmlConverter.php index 7162b256d..944cb081b 100644 --- a/vendor/league/html-to-markdown/src/HtmlConverter.php +++ b/vendor/league/html-to-markdown/src/HtmlConverter.php @@ -212,7 +212,7 @@ class HtmlConverter implements HtmlConverterInterface $tag = $element->getTagName(); // Strip nodes named in remove_nodes - $tagsToRemove = \explode(' ', $this->getConfig()->getOption('remove_nodes') ?? ''); + $tagsToRemove = \explode(' ', Coerce::toString($this->getConfig()->getOption('remove_nodes') ?? '')); if (\in_array($tag, $tagsToRemove, true)) { return ''; } |