aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/league/html-to-markdown/src/Converter/PreformattedConverter.php
diff options
context:
space:
mode:
authorMario Vavti <mario@mariovavti.com>2018-01-12 22:32:42 +0100
committerMario Vavti <mario@mariovavti.com>2018-01-12 22:32:42 +0100
commit0f5bc00586e5fb9e3f251dc8dbd58579bb3381a9 (patch)
tree045e8b9dedc7b812bfbaa301e5cb67b12678df69 /vendor/league/html-to-markdown/src/Converter/PreformattedConverter.php
parent50ec3b300be81cfd652e2f0ed63ab180cc25a141 (diff)
downloadvolse-hubzilla-0f5bc00586e5fb9e3f251dc8dbd58579bb3381a9.tar.gz
volse-hubzilla-0f5bc00586e5fb9e3f251dc8dbd58579bb3381a9.tar.bz2
volse-hubzilla-0f5bc00586e5fb9e3f251dc8dbd58579bb3381a9.zip
update league/html-to-markdown via composer
Diffstat (limited to 'vendor/league/html-to-markdown/src/Converter/PreformattedConverter.php')
-rw-r--r--vendor/league/html-to-markdown/src/Converter/PreformattedConverter.php23
1 files changed, 15 insertions, 8 deletions
diff --git a/vendor/league/html-to-markdown/src/Converter/PreformattedConverter.php b/vendor/league/html-to-markdown/src/Converter/PreformattedConverter.php
index 7a4ec3357..0bb89e90f 100644
--- a/vendor/league/html-to-markdown/src/Converter/PreformattedConverter.php
+++ b/vendor/league/html-to-markdown/src/Converter/PreformattedConverter.php
@@ -33,20 +33,27 @@ class PreformattedConverter implements ConverterInterface
// If the execution reaches this point it means it's just a pre tag, with no code tag nested
+ // Empty lines are a special case
+ if ($pre_content === '') {
+ return "```\n```\n";
+ }
+
// Normalizing new lines
$pre_content = preg_replace('/\r\n|\r|\n/', PHP_EOL, $pre_content);
- // Checking if the string has multiple lines
- $lines = preg_split('/\r\n|\r|\n/', $pre_content);
- if (count($lines) > 1) {
- // Multiple lines detected, adding three backticks and newlines
- $markdown .= '```' . "\n" . $pre_content . "\n" . '```';
- } else {
+ // Is it a single line?
+ if (strpos($pre_content, PHP_EOL) === false) {
// One line of code, wrapping it on one backtick.
- $markdown .= '`' . $pre_content . '`';
+ return '`' . $pre_content . '`';
+ }
+
+ // Ensure there's a newline at the end
+ if (strrpos($pre_content, PHP_EOL) !== strlen($pre_content) - 1) {
+ $pre_content .= PHP_EOL;
}
- return $markdown;
+ // Use three backticks
+ return "```\n" . $pre_content . "```\n";
}
/**