diff --git a/markdownify/__init__.py b/markdownify/__init__.py index d946d2c..3072050 100644 --- a/markdownify/__init__.py +++ b/markdownify/__init__.py @@ -45,6 +45,10 @@ # Find consecutive backtick sequences in a string re_backtick_runs = re.compile(r'`+') +# Find pipes that are not already escaped, so they can be escaped inside +# table cells without touching escapes that escape_misc already added +re_escape_table_pipe = re.compile(r'(? + Expression + a|b + a|b +""" + + +def test_table_pipes_are_escaped(): + assert md(table_with_pipes) == ( + '\n\n| Expression |\n| --- |\n' + '| a\\|b |\n' + '| `a\\|b` |\n\n' + ) + + +def test_table_pipes_not_double_escaped(): + assert md(table_with_pipes, escape_misc=True) == ( + '\n\n| Expression |\n| --- |\n' + '| a\\|b |\n' + '| `a\\|b` |\n\n' + )