diff --git a/src/Converter/ParagraphConverter.php b/src/Converter/ParagraphConverter.php index 6e8b57e..b996dca 100644 --- a/src/Converter/ParagraphConverter.php +++ b/src/Converter/ParagraphConverter.php @@ -47,6 +47,7 @@ private function escapeSpecialCharacters($line) { $line = $this->escapeHeaderlikeCharacters($line); $line = $this->escapeBlockquotelikeCharacters($line); + $line = $this->escapeOrderedListlikeCharacters($line); return $line; } @@ -80,4 +81,20 @@ private function escapeHeaderlikeCharacters($line) return $line; } } + + /** + * @param string $line + * + * @return string + */ + private function escapeOrderedListlikeCharacters($line) + { + // This regex will match numbers ending on ')' or '.' that are at the beginning of the line. + if (preg_match('/^[0-9]+(?=\)|\.)/', $line, $match)) { + // Found an Ordered list like character, escaping it + return substr_replace($line, '\\', strlen($match[0]), 0); + } else { + return $line; + } + } } diff --git a/tests/HtmlConverterTest.php b/tests/HtmlConverterTest.php index ce0fa43..cc32baf 100644 --- a/tests/HtmlConverterTest.php +++ b/tests/HtmlConverterTest.php @@ -219,5 +219,6 @@ public function test_sanitization() $this->html_gives_markdown('

> > Look at me! < <

', '\> > Look at me! < <'); $this->html_gives_markdown('

> > Look at me! < <
> Just look at me!

', "\\> > **Look** at me! < < \n\\> Just look at me!"); $this->html_gives_markdown('

Foo
--
Bar
Foo--

', "Foo \n\\-- \nBar \nFoo--"); + $this->html_gives_markdown("

123456789) Foo and 1234567890) Bar!

\n

1. Platz in 'Das große Backen'

", "123456789\\) Foo and 1234567890) Bar!\n\n1\\. Platz in 'Das große Backen'"); } }