aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/league/html-to-markdown/src/Converter/PreformattedConverter.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/league/html-to-markdown/src/Converter/PreformattedConverter.php')
-rw-r--r--vendor/league/html-to-markdown/src/Converter/PreformattedConverter.php18
1 files changed, 5 insertions, 13 deletions
diff --git a/vendor/league/html-to-markdown/src/Converter/PreformattedConverter.php b/vendor/league/html-to-markdown/src/Converter/PreformattedConverter.php
index 3b77ba10b..321c898b1 100644
--- a/vendor/league/html-to-markdown/src/Converter/PreformattedConverter.php
+++ b/vendor/league/html-to-markdown/src/Converter/PreformattedConverter.php
@@ -13,8 +13,6 @@ class PreformattedConverter implements ConverterInterface
*/
public function convert(ElementInterface $element)
{
- $markdown = '';
-
$pre_content = html_entity_decode($element->getChildrenAsString());
$pre_content = str_replace(array('<pre>', '</pre>'), '', $pre_content);
@@ -28,28 +26,22 @@ class PreformattedConverter implements ConverterInterface
$firstBacktick = strpos(trim($pre_content), '`');
$lastBacktick = strrpos(trim($pre_content), '`');
if ($firstBacktick === 0 && $lastBacktick === strlen(trim($pre_content)) - 1) {
- return $pre_content;
+ return $pre_content . "\n\n";
}
// 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";
+ return "```\n```\n\n";
}
// Normalizing new lines
- $pre_content = preg_replace('/\r\n|\r|\n/', PHP_EOL, $pre_content);
-
- // Is it a single line?
- if (strpos($pre_content, PHP_EOL) === false) {
- // One line of code, wrapping it on one backtick.
- return '`' . $pre_content . '`';
- }
+ $pre_content = preg_replace('/\r\n|\r|\n/', "\n", $pre_content);
// Ensure there's a newline at the end
- if (strrpos($pre_content, PHP_EOL) !== strlen($pre_content) - 1) {
- $pre_content .= PHP_EOL;
+ if (strrpos($pre_content, "\n") !== strlen($pre_content) - strlen("\n")) {
+ $pre_content .= "\n";
}
// Use three backticks