diff options
author | nobody <nobody@zotlabs.com> | 2021-06-17 14:57:47 -0700 |
---|---|---|
committer | nobody <nobody@zotlabs.com> | 2021-06-17 14:57:47 -0700 |
commit | efda8aac1d7d90fd7eda4a449332eedf74342951 (patch) | |
tree | 3373c0579168776cccda5224b6b33ce59fa9b274 /vendor/league/html-to-markdown/src/Converter/ParagraphConverter.php | |
parent | 686530c1873f98d724355bf3f456243b1b7fdadd (diff) | |
parent | a84cec4acddf6804a88fcda52e4437c91785dfb2 (diff) | |
download | volse-hubzilla-efda8aac1d7d90fd7eda4a449332eedf74342951.tar.gz volse-hubzilla-efda8aac1d7d90fd7eda4a449332eedf74342951.tar.bz2 volse-hubzilla-efda8aac1d7d90fd7eda4a449332eedf74342951.zip |
Merge branch 'dev' of https://framagit.org/hubzilla/core into dev
Diffstat (limited to 'vendor/league/html-to-markdown/src/Converter/ParagraphConverter.php')
-rw-r--r-- | vendor/league/html-to-markdown/src/Converter/ParagraphConverter.php | 85 |
1 files changed, 34 insertions, 51 deletions
diff --git a/vendor/league/html-to-markdown/src/Converter/ParagraphConverter.php b/vendor/league/html-to-markdown/src/Converter/ParagraphConverter.php index 7207b81a6..65b37a4db 100644 --- a/vendor/league/html-to-markdown/src/Converter/ParagraphConverter.php +++ b/vendor/league/html-to-markdown/src/Converter/ParagraphConverter.php @@ -1,23 +1,22 @@ <?php +declare(strict_types=1); + namespace League\HTMLToMarkdown\Converter; use League\HTMLToMarkdown\ElementInterface; class ParagraphConverter implements ConverterInterface { - /** - * @param ElementInterface $element - * - * @return string - */ - public function convert(ElementInterface $element) + public function convert(ElementInterface $element): string { $value = $element->getValue(); $markdown = ''; - $lines = preg_split('/\r\n|\r|\n/', $value); + $lines = \preg_split('/\r\n|\r|\n/', $value); + \assert($lines !== false); + foreach ($lines as $line) { /* * Some special characters need to be escaped based on the position that they appear @@ -27,23 +26,18 @@ class ParagraphConverter implements ConverterInterface $markdown .= "\n"; } - return trim($markdown) !== '' ? rtrim($markdown) . "\n\n" : ''; + return \trim($markdown) !== '' ? \rtrim($markdown) . "\n\n" : ''; } /** * @return string[] */ - public function getSupportedTags() + public function getSupportedTags(): array { - return array('p'); + return ['p']; } - /** - * @param string $line - * - * @return string - */ - private function escapeSpecialCharacters($line) + private function escapeSpecialCharacters(string $line): string { $line = $this->escapeFirstCharacters($line); $line = $this->escapeOtherCharacters($line); @@ -52,72 +46,61 @@ class ParagraphConverter implements ConverterInterface return $line; } - /** - * @param string $line - * - * @return string - */ - private function escapeFirstCharacters($line) + private function escapeFirstCharacters(string $line): string { - $escapable = array( + $escapable = [ '>', '- ', '+ ', '--', '~~~', '---', - '- - -' - ); + '- - -', + ]; foreach ($escapable as $i) { - if (strpos(ltrim($line), $i) === 0) { + if (\strpos(\ltrim($line), $i) === 0) { // Found a character that must be escaped, adding a backslash before - return '\\' . ltrim($line); + return '\\' . \ltrim($line); } } return $line; } - /** - * @param string $line - * - * @return string - */ - private function escapeOtherCharacters($line) + private function escapeOtherCharacters(string $line): string { - $escapable = array( - '<!--' - ); + $escapable = [ + '<!--', + ]; foreach ($escapable as $i) { - if (strpos($line, $i) !== false) { - // Found an escapable character, escaping it - $line = substr_replace($line, '\\', strpos($line, $i), 0); + if (($pos = \strpos($line, $i)) === false) { + continue; } + + // Found an escapable character, escaping it + $line = \substr_replace($line, '\\', $pos, 0); } return $line; } - /** - * @param string $line - * - * @return string - */ - private function escapeOtherCharactersRegex($line) + private function escapeOtherCharactersRegex(string $line): string { - $regExs = array( + $regExs = [ // Match numbers ending on ')' or '.' that are at the beginning of the line. // They will be escaped if immediately followed by a space or newline. - '/^[0-9]+(?=(\)|\.)( |$))/' - ); + '/^[0-9]+(?=(\)|\.)( |$))/', + ]; foreach ($regExs as $i) { - if (preg_match($i, $line, $match)) { - // Matched an escapable character, adding a backslash on the string before the offending character - $line = substr_replace($line, '\\', strlen($match[0]), 0); + if (! \preg_match($i, $line, $match)) { + continue; } + + // Matched an escapable character, adding a backslash on the string before the offending character + $line = \substr_replace($line, '\\', \strlen($match[0]), 0); } return $line; |