Skip to content

Commit

Permalink
Merge pull request #106 from andreskrey/master-issue73-orderedlist
Browse files Browse the repository at this point in the history
Escaping ordered list-like lines
  • Loading branch information
colinodell authored Oct 25, 2016
2 parents d5752df + 0f27aa0 commit 96dd9be
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Converter/ParagraphConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ private function escapeSpecialCharacters($line)
{
$line = $this->escapeHeaderlikeCharacters($line);
$line = $this->escapeBlockquotelikeCharacters($line);
$line = $this->escapeOrderedListlikeCharacters($line);

return $line;
}
Expand Down Expand Up @@ -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;
}
}
}
1 change: 1 addition & 0 deletions tests/HtmlConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,5 +219,6 @@ 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("<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'");
}
}

0 comments on commit 96dd9be

Please sign in to comment.