diff options
Diffstat (limited to 'vendor/league/html-to-markdown/src')
5 files changed, 44 insertions, 5 deletions
diff --git a/vendor/league/html-to-markdown/src/Converter/CommentConverter.php b/vendor/league/html-to-markdown/src/Converter/CommentConverter.php index 55038b254..959381d1b 100644 --- a/vendor/league/html-to-markdown/src/Converter/CommentConverter.php +++ b/vendor/league/html-to-markdown/src/Converter/CommentConverter.php @@ -2,17 +2,35 @@ namespace League\HTMLToMarkdown\Converter; +use League\HTMLToMarkdown\Configuration; +use League\HTMLToMarkdown\ConfigurationAwareInterface; use League\HTMLToMarkdown\ElementInterface; -class CommentConverter implements ConverterInterface +class CommentConverter implements ConverterInterface, ConfigurationAwareInterface { /** + * @var Configuration + */ + protected $config; + + /** + * @param Configuration $config + */ + public function setConfig(Configuration $config) + { + $this->config = $config; + } + + /** * @param ElementInterface $element * * @return string */ public function convert(ElementInterface $element) { + if ($this->shouldPreserve($element)) { + return '<!--' . $element->getValue() . '-->'; + } return ''; } @@ -23,4 +41,22 @@ class CommentConverter implements ConverterInterface { return array('#comment'); } + + /** + * @param ElementInterface $element + * + * @return bool + */ + private function shouldPreserve(ElementInterface $element) + { + $preserve = $this->config->getOption('preserve_comments'); + if ($preserve === true) { + return true; + } + if (is_array($preserve)) { + $value = trim($element->getValue()); + return in_array($value, $preserve); + } + 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 05d4fe81e..353833263 100644 --- a/vendor/league/html-to-markdown/src/Converter/HeaderConverter.php +++ b/vendor/league/html-to-markdown/src/Converter/HeaderConverter.php @@ -35,7 +35,7 @@ class HeaderConverter implements ConverterInterface, ConfigurationAwareInterface $style = $this->config->getOption('header_style', self::STYLE_SETEXT); if (strlen($element->getValue()) === 0) { - return ''; + return "\n"; } if (($level === 1 || $level === 2) && !$element->isDescendantOf('blockquote') && $style === self::STYLE_SETEXT) { diff --git a/vendor/league/html-to-markdown/src/Converter/LinkConverter.php b/vendor/league/html-to-markdown/src/Converter/LinkConverter.php index c82b70e97..81c18b65f 100644 --- a/vendor/league/html-to-markdown/src/Converter/LinkConverter.php +++ b/vendor/league/html-to-markdown/src/Converter/LinkConverter.php @@ -24,6 +24,9 @@ class LinkConverter implements ConverterInterface } elseif ($href === 'mailto:' . $text && $this->isValidEmail($text)) { $markdown = '<' . $text . '>'; } else { + if (stristr($href, ' ')) { + $href = '<'.$href.'>'; + } $markdown = '[' . $text . '](' . $href . ')'; } diff --git a/vendor/league/html-to-markdown/src/Element.php b/vendor/league/html-to-markdown/src/Element.php index e1e9d1a09..80ae7a911 100644 --- a/vendor/league/html-to-markdown/src/Element.php +++ b/vendor/league/html-to-markdown/src/Element.php @@ -27,7 +27,6 @@ class Element implements ElementInterface switch ($this->getTagName()) { case 'blockquote': case 'body': - case 'code': case 'div': case 'h1': case 'h2': diff --git a/vendor/league/html-to-markdown/src/HtmlConverter.php b/vendor/league/html-to-markdown/src/HtmlConverter.php index 3381e1e1e..846131af6 100644 --- a/vendor/league/html-to-markdown/src/HtmlConverter.php +++ b/vendor/league/html-to-markdown/src/HtmlConverter.php @@ -40,6 +40,7 @@ class HtmlConverter implements HtmlConverterInterface 'remove_nodes' => '', // space-separated list of dom nodes that should be removed. example: 'meta style script' 'hard_break' => false, // Set to true to turn <br> into `\n` instead of ` \n` 'list_item_style' => '-', // Set the default character for each <li> in a <ul>. Can be '-', '*', or '+' + 'preserve_comments' => false, // Set to true to preserve comments, or set to an array of strings to preserve specific comments ); $this->environment = Environment::createDefaultEnvironment($defaults); @@ -229,13 +230,13 @@ class HtmlConverter implements HtmlConverterInterface return trim($markdown, "\n\r\0\x0B"); } - + /** * Pass a series of key-value pairs in an array; these will be passed * through the config and set. * The advantage of this is that it can allow for static use (IE in Laravel). * An example being: - * + * * HtmlConverter::setOptions(['strip_tags' => true])->convert('<h1>test</h1>'); */ public function setOptions(array $options) |