diff --git a/markdown/__init__.py b/markdown/__init__.py index 78ea4cbe6..409f9cfd4 100644 --- a/markdown/__init__.py +++ b/markdown/__init__.py @@ -75,9 +75,6 @@ class Markdown(object): 'xhtml5': to_xhtml_string, } - ESCAPED_CHARS = ['\\', '`', '*', '_', '{', '}', '[', ']', - '(', ')', '>', '#', '+', '-', '.', '!'] - def __init__(self, *args, **kwargs): """ Creates a new Markdown instance. @@ -147,6 +144,9 @@ def __init__(self, *args, **kwargs): 'deprecated along with "safe_mode".', DeprecationWarning) + self.ESCAPED_CHARS = ['\\', '`', '*', '_', '{', '}', '[', ']', + '(', ')', '>', '#', '+', '-', '.', '!'] + self.registeredExtensions = [] self.docType = "" self.stripTopLevelTags = True diff --git a/markdown/extensions/tables.py b/markdown/extensions/tables.py index 4bb20767e..4f12bfd88 100644 --- a/markdown/extensions/tables.py +++ b/markdown/extensions/tables.py @@ -160,6 +160,8 @@ class TableExtension(Extension): def extendMarkdown(self, md, md_globals): """ Add an instance of TableProcessor to BlockParser. """ + if '|' not in md.ESCAPED_CHARS: + md.ESCAPED_CHARS.append('|') md.parser.blockprocessors.add('table', TableProcessor(md.parser), 'Table Tests \ + +

Test escaped pipes

+ + + + + + + + + + + + +
Column1Column 2
| |Pipes are okay in code and escaped. |
\ No newline at end of file diff --git a/tests/extensions/extra/tables.txt b/tests/extensions/extra/tables.txt index a9677ba8e..705fc14b3 100644 --- a/tests/extensions/extra/tables.txt +++ b/tests/extensions/extra/tables.txt @@ -90,3 +90,9 @@ Odd backticks | Even backticks Escapes | More Escapes ------- | ------ `` `\`` | `\` + +Test escaped pipes + +Column1 | Column 2 +------- | -------- +`|` \| | Pipes are okay in code and escaped. \| diff --git a/tests/test_apis.py b/tests/test_apis.py index e3de779dd..7b1214fba 100644 --- a/tests/test_apis.py +++ b/tests/test_apis.py @@ -758,3 +758,15 @@ def testExtensonConfigOptionBadFormat(self): """ self.create_config_file(config) self.assertRaises(yaml.YAMLError, parse_options, ['-c', self.tempfile]) + + +class TestEscapeAppend(unittest.TestCase): + """ Tests escape character append. """ + + def testAppend(self): + """ Test that appended escapes are only in the current instance. """ + md = markdown.Markdown() + md.ESCAPED_CHARS.append('|') + self.assertEqual('|' in md.ESCAPED_CHARS, True) + md2 = markdown.Markdown() + self.assertEqual('|' not in md2.ESCAPED_CHARS, True)