aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/league/html-to-markdown/src/Converter
diff options
context:
space:
mode:
authorMario Vavti <mario@mariovavti.com>2018-10-30 12:12:07 +0100
committerMario Vavti <mario@mariovavti.com>2018-10-30 12:12:07 +0100
commit2192ea6fdf21a00ccf44d626a01b756d194d6cbe (patch)
tree153d4b4ffb2bf40edf8aae66b82a274dac37c208 /vendor/league/html-to-markdown/src/Converter
parent0f19627407ccd373afe1ce2d2347ea240f3195c1 (diff)
downloadvolse-hubzilla-2192ea6fdf21a00ccf44d626a01b756d194d6cbe.tar.gz
volse-hubzilla-2192ea6fdf21a00ccf44d626a01b756d194d6cbe.tar.bz2
volse-hubzilla-2192ea6fdf21a00ccf44d626a01b756d194d6cbe.zip
update html_to_markdown, smarty and sabredav libs via composer
Diffstat (limited to 'vendor/league/html-to-markdown/src/Converter')
-rw-r--r--vendor/league/html-to-markdown/src/Converter/CodeConverter.php37
-rw-r--r--vendor/league/html-to-markdown/src/Converter/HeaderConverter.php4
-rw-r--r--vendor/league/html-to-markdown/src/Converter/LinkConverter.php13
-rw-r--r--vendor/league/html-to-markdown/src/Converter/PreformattedConverter.php18
-rw-r--r--vendor/league/html-to-markdown/src/Converter/TextConverter.php4
5 files changed, 52 insertions, 24 deletions
diff --git a/vendor/league/html-to-markdown/src/Converter/CodeConverter.php b/vendor/league/html-to-markdown/src/Converter/CodeConverter.php
index e536362ee..39e6a7bc4 100644
--- a/vendor/league/html-to-markdown/src/Converter/CodeConverter.php
+++ b/vendor/league/html-to-markdown/src/Converter/CodeConverter.php
@@ -13,7 +13,7 @@ class CodeConverter implements ConverterInterface
*/
public function convert(ElementInterface $element)
{
- $language = null;
+ $language = '';
// Checking for language class on the code block
$classes = $element->getAttribute('class');
@@ -24,8 +24,7 @@ class CodeConverter implements ConverterInterface
foreach ($classes as $class) {
if (strpos($class, 'language-') !== false) {
// Found one, save it as the selected language and stop looping over the classes.
- // The space after the language avoids gluing the actual code with the language tag
- $language = str_replace('language-', '', $class) . ' ';
+ $language = str_replace('language-', '', $class);
break;
}
}
@@ -39,14 +38,13 @@ class CodeConverter implements ConverterInterface
$code = preg_replace('/<code\b[^>]*>/', '', $code);
$code = str_replace('</code>', '', $code);
- // Checking if the code has multiple lines
- $lines = preg_split('/\r\n|\r|\n/', $code);
- if (count($lines) > 1) {
- // Multiple lines detected, adding three backticks and newlines
- $markdown .= '```' . $language . "\n" . $code . "\n" . '```' . "\n\n";
+ // Checking if it's a code block or span
+ if ($this->shouldBeBlock($element, $code)) {
+ // Code block detected, newlines will be added in parent
+ $markdown .= '```' . $language . "\n" . $code . "\n" . '```';
} else {
- // One line of code, wrapping it on one backtick.
- $markdown .= '`' . $language . $code . '`';
+ // One line of code, wrapping it on one backtick, removing new lines
+ $markdown .= '`' . preg_replace('/\r\n|\r|\n/', '', $code) . '`';
}
return $markdown;
@@ -59,4 +57,23 @@ class CodeConverter implements ConverterInterface
{
return array('code');
}
+
+ /**
+ * @param ElementInterface $element
+ * @param string $code
+ *
+ * @return bool
+ */
+ private function shouldBeBlock(ElementInterface $element, $code)
+ {
+ if ($element->getParent()->getTagName() == 'pre') {
+ return true;
+ }
+
+ if (preg_match('/[^\s]` `/', $code)) {
+ return true;
+ }
+
+ return false;
+ }
}
diff --git a/vendor/league/html-to-markdown/src/Converter/HeaderConverter.php b/vendor/league/html-to-markdown/src/Converter/HeaderConverter.php
index d117e7d36..05d4fe81e 100644
--- a/vendor/league/html-to-markdown/src/Converter/HeaderConverter.php
+++ b/vendor/league/html-to-markdown/src/Converter/HeaderConverter.php
@@ -34,6 +34,10 @@ class HeaderConverter implements ConverterInterface, ConfigurationAwareInterface
$level = (int) substr($element->getTagName(), 1, 1);
$style = $this->config->getOption('header_style', self::STYLE_SETEXT);
+ if (strlen($element->getValue()) === 0) {
+ return '';
+ }
+
if (($level === 1 || $level === 2) && !$element->isDescendantOf('blockquote') && $style === self::STYLE_SETEXT) {
return $this->createSetextHeader($level, $element->getValue());
}
diff --git a/vendor/league/html-to-markdown/src/Converter/LinkConverter.php b/vendor/league/html-to-markdown/src/Converter/LinkConverter.php
index 74b49a778..c82b70e97 100644
--- a/vendor/league/html-to-markdown/src/Converter/LinkConverter.php
+++ b/vendor/league/html-to-markdown/src/Converter/LinkConverter.php
@@ -21,6 +21,8 @@ class LinkConverter implements ConverterInterface
$markdown = '[' . $text . '](' . $href . ' "' . $title . '")';
} elseif ($href === $text && $this->isValidAutolink($href)) {
$markdown = '<' . $href . '>';
+ } elseif ($href === 'mailto:' . $text && $this->isValidEmail($text)) {
+ $markdown = '<' . $text . '>';
} else {
$markdown = '[' . $text . '](' . $href . ')';
}
@@ -49,4 +51,15 @@ class LinkConverter implements ConverterInterface
{
return preg_match('/^[A-Za-z][A-Za-z0-9.+-]{1,31}:[^<>\x00-\x20]*/i', $href) === 1;
}
+
+ /**
+ * @param string $email
+ *
+ * @return bool
+ */
+ private function isValidEmail($email)
+ {
+ // Email validation is messy business, but this should cover most cases
+ return filter_var($email, FILTER_VALIDATE_EMAIL);
+ }
}
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
diff --git a/vendor/league/html-to-markdown/src/Converter/TextConverter.php b/vendor/league/html-to-markdown/src/Converter/TextConverter.php
index d6d91e16f..fcd466094 100644
--- a/vendor/league/html-to-markdown/src/Converter/TextConverter.php
+++ b/vendor/league/html-to-markdown/src/Converter/TextConverter.php
@@ -22,7 +22,9 @@ class TextConverter implements ConverterInterface
$markdown = preg_replace('~\s+~u', ' ', $markdown);
// Escape the following characters: '*', '_', '[', ']' and '\'
- $markdown = preg_replace('~([*_\\[\\]\\\\])~u', '\\\\$1', $markdown);
+ if ($element->getParent() && $element->getParent()->getTagName() !== 'div') {
+ $markdown = preg_replace('~([*_\\[\\]\\\\])~u', '\\\\$1', $markdown);
+ }
$markdown = preg_replace('~^#~u', '\\\\#', $markdown);