aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/league/html-to-markdown/src/Converter/ParagraphConverter.php
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2021-06-05 08:47:24 +0000
committerMario <mario@mariovavti.com>2021-06-05 08:47:24 +0000
commitfd8a5ff4c49fc1361f9928ea4d33e6d24d43a3a5 (patch)
tree7560147f31a273fb8f0e05476f99f1deea0e12de /vendor/league/html-to-markdown/src/Converter/ParagraphConverter.php
parent4db384da34595adef68be6226e8b331b4d7b7f31 (diff)
downloadvolse-hubzilla-fd8a5ff4c49fc1361f9928ea4d33e6d24d43a3a5.tar.gz
volse-hubzilla-fd8a5ff4c49fc1361f9928ea4d33e6d24d43a3a5.tar.bz2
volse-hubzilla-fd8a5ff4c49fc1361f9928ea4d33e6d24d43a3a5.zip
composer update league/html-to-markdown
Diffstat (limited to 'vendor/league/html-to-markdown/src/Converter/ParagraphConverter.php')
-rw-r--r--vendor/league/html-to-markdown/src/Converter/ParagraphConverter.php85
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;