diff --git a/README.rst b/README.rst index 55ea7cf..98473c6 100644 --- a/README.rst +++ b/README.rst @@ -128,9 +128,9 @@ escape_underscores Defaults to ``True``. escape_misc - If set to ``False``, do not escape miscellaneous punctuation characters + If set to ``True``, escape miscellaneous punctuation characters that sometimes have Markdown significance in text. - Defaults to ``True``. + Defaults to ``False``. keep_inline_images_in Images are converted to their alt-text when the images are located inside diff --git a/markdownify/__init__.py b/markdownify/__init__.py index 9951d5b..5c90129 100644 --- a/markdownify/__init__.py +++ b/markdownify/__init__.py @@ -94,7 +94,7 @@ class DefaultOptions: default_title = False escape_asterisks = True escape_underscores = True - escape_misc = True + escape_misc = False heading_style = UNDERLINED keep_inline_images_in = [] newline_style = SPACES diff --git a/tests/test_escaping.py b/tests/test_escaping.py index 6b21f68..878760a 100644 --- a/tests/test_escaping.py +++ b/tests/test_escaping.py @@ -14,7 +14,7 @@ def test_underscore(): def test_xml_entities(): - assert md('&') == r'\&' + assert md('&', escape_misc=True) == r'\&' def test_named_entities(): @@ -27,49 +27,49 @@ def test_hexadecimal_entities(): def test_single_escaping_entities(): - assert md('&amp;') == r'\&' + assert md('&amp;', escape_misc=True) == r'\&' def test_misc(): # ignore the bs4 warning that "1.2" or "*" looks like a filename warnings.filterwarnings("ignore", category=MarkupResemblesLocatorWarning) - assert md('\\*') == r'\\\*' - assert md('<foo>') == r'\' - assert md('# foo') == r'\# foo' - assert md('#5') == r'#5' - assert md('5#') == '5#' - assert md('####### foo') == r'####### foo' - assert md('> foo') == r'\> foo' - assert md('~~foo~~') == r'\~\~foo\~\~' - assert md('foo\n===\n') == 'foo\n\\=\\=\\=\n' - assert md('---\n') == '\\---\n' - assert md('- test') == r'\- test' - assert md('x - y') == r'x \- y' - assert md('test-case') == 'test-case' - assert md('x-') == 'x-' - assert md('-y') == '-y' - assert md('+ x\n+ y\n') == '\\+ x\n\\+ y\n' - assert md('`x`') == r'\`x\`' - assert md('[text](link)') == r'\[text](link)' - assert md('1. x') == r'1\. x' - # assert md('1. x') == r'1\. x' - assert md('1. x') == r'1\. x' - assert md(' 1. x') == r' 1\. x' - assert md('123456789. x') == r'123456789\. x' - assert md('1234567890. x') == r'1234567890. x' - assert md('A1. x') == r'A1. x' - assert md('1.2') == r'1.2' - assert md('not a number. x') == r'not a number. x' - assert md('1) x') == r'1\) x' - # assert md('1) x') == r'1\) x' - assert md('1) x') == r'1\) x' - assert md(' 1) x') == r' 1\) x' - assert md('123456789) x') == r'123456789\) x' - assert md('1234567890) x') == r'1234567890) x' - assert md('(1) x') == r'(1) x' - assert md('A1) x') == r'A1) x' - assert md('1)x') == r'1)x' - assert md('not a number) x') == r'not a number) x' - assert md('|not table|') == r'\|not table\|' + assert md('\\*', escape_misc=True) == r'\\\*' + assert md('<foo>', escape_misc=True) == r'\' + assert md('# foo', escape_misc=True) == r'\# foo' + assert md('#5', escape_misc=True) == r'#5' + assert md('5#', escape_misc=True) == '5#' + assert md('####### foo', escape_misc=True) == r'####### foo' + assert md('> foo', escape_misc=True) == r'\> foo' + assert md('~~foo~~', escape_misc=True) == r'\~\~foo\~\~' + assert md('foo\n===\n', escape_misc=True) == 'foo\n\\=\\=\\=\n' + assert md('---\n', escape_misc=True) == '\\---\n' + assert md('- test', escape_misc=True) == r'\- test' + assert md('x - y', escape_misc=True) == r'x \- y' + assert md('test-case', escape_misc=True) == 'test-case' + assert md('x-', escape_misc=True) == 'x-' + assert md('-y', escape_misc=True) == '-y' + assert md('+ x\n+ y\n', escape_misc=True) == '\\+ x\n\\+ y\n' + assert md('`x`', escape_misc=True) == r'\`x\`' + assert md('[text](link)', escape_misc=True) == r'\[text](link)' + assert md('1. x', escape_misc=True) == r'1\. x' + # assert md('1. x', escape_misc=True) == r'1\. x' + assert md('1. x', escape_misc=True) == r'1\. x' + assert md(' 1. x', escape_misc=True) == r' 1\. x' + assert md('123456789. x', escape_misc=True) == r'123456789\. x' + assert md('1234567890. x', escape_misc=True) == r'1234567890. x' + assert md('A1. x', escape_misc=True) == r'A1. x' + assert md('1.2', escape_misc=True) == r'1.2' + assert md('not a number. x', escape_misc=True) == r'not a number. x' + assert md('1) x', escape_misc=True) == r'1\) x' + # assert md('1) x', escape_misc=True) == r'1\) x' + assert md('1) x', escape_misc=True) == r'1\) x' + assert md(' 1) x', escape_misc=True) == r' 1\) x' + assert md('123456789) x', escape_misc=True) == r'123456789\) x' + assert md('1234567890) x', escape_misc=True) == r'1234567890) x' + assert md('(1) x', escape_misc=True) == r'(1) x' + assert md('A1) x', escape_misc=True) == r'A1) x' + assert md('1)x', escape_misc=True) == r'1)x' + assert md('not a number) x', escape_misc=True) == r'not a number) x' + assert md('|not table|', escape_misc=True) == r'\|not table\|' assert md(r'\ <foo> &amp; | ` `', escape_misc=False) == r'\ & | ` `'