Fix handling of backslashes in relation to code blocks (#203)

Backslashes are now correctly preserved inside code blocks while still allowing the user to escape a backtick. The handling of backticks and bold/italic wrappers was unified so that they share the same escaping code.

Backslashes only escape Markdown wrapper characters (*, _, `). If they are encountered before another character, they are considered literal.
This commit is contained in:
Tom Smeding 2020-06-03 13:06:16 +02:00 committed by GitHub
parent 3cf5cc077e
commit a5e6434c31
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 60 additions and 31 deletions

View file

@ -109,6 +109,16 @@ def test_input_line_markdown_various2():
assert "norm** <code>code **code *code</code> norm `norm" \
== formatted.to_html()
def test_input_line_backslash():
def convert(s): return Formatted.from_input_line(s).to_html()
assert "pre <em>italic* ital</em> norm" == convert("pre *italic\\* ital* norm")
assert "*norm* norm" == convert("\\*norm* norm")
assert "<em>*ital</em>" == convert("*\\*ital*")
assert "<code>C:\\path</code>" == convert("`C:\\path`")
assert "<code>with`tick</code>" == convert("`with\\`tick`")
assert "`un`matched" == convert("`un\\`matched")
assert "<strong>bold </strong><em><strong>*bital</strong></em> norm" == convert("**bold *\\*bital*** norm")
def test_conversion():
formatted = Formatted.from_input_line("*Hello*")
formatted2 = Formatted.from_html(formatted.to_html())