Skip to content

Commit

Permalink
Merge pull request #159 from Sylry/escape_list_like_lines_inside_list…
Browse files Browse the repository at this point in the history
…e_item

Escape list-like lines inside list item.
  • Loading branch information
colinodell authored May 19, 2018
2 parents 3af14d8 + 158968f commit 5fdd7d4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/Converter/HardBreakConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,19 @@ public function setConfig(Configuration $config)
*/
public function convert(ElementInterface $element)
{
return $this->config->getOption('hard_break') ? "\n" : " \n";
$return = $this->config->getOption('hard_break') ? "\n" : " \n";

$next = $element->getNext();
if ($next) {
$next_value = $next->getValue();
if ($next_value) {
if (in_array(substr($next_value, 0, 2), array('- ', '* ', '+ '))) {
$return .= '\\';
}
}
}

return $return;
}

/**
Expand Down
1 change: 1 addition & 0 deletions tests/HtmlConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ public function test_sanitization()
$this->html_gives_markdown('<p>&gt; &gt; Look at me! &lt; &lt;</p>', '\> > Look at me! < <');
$this->html_gives_markdown('<p>&gt; &gt; <b>Look</b> at me! &lt; &lt;<br />&gt; Just look at me!</p>', "\\> > **Look** at me! < < \n\\> Just look at me!");
$this->html_gives_markdown('<p>Foo<br>--<br>Bar<br>Foo--</p>', "Foo \n\\-- \nBar \nFoo--");
$this->html_gives_markdown('<ul><li>Foo<br>- Bar</li></ul>', "- Foo \n \\- Bar");
$this->html_gives_markdown("<p>123456789) Foo and 1234567890) Bar!</p>\n<p>1. Platz in 'Das große Backen'</p>", "123456789\\) Foo and 1234567890) Bar!\n\n1\\. Platz in 'Das große Backen'");
$this->html_gives_markdown("<p>\n+ Siri works well for TV and movies<br>\n- No 4K support\n</p>", "\+ Siri works well for TV and movies \n\- No 4K support");
$this->html_gives_markdown('<p>You forgot the &lt;!--more--&gt; tag!</p>', 'You forgot the \<!--more--> tag!');
Expand Down

0 comments on commit 5fdd7d4

Please sign in to comment.