Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions markdown/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ class Markdown(object):
'xhtml5': to_xhtml_string,
}

ESCAPED_CHARS = ['\\', '`', '*', '_', '{', '}', '[', ']',
'(', ')', '>', '#', '+', '-', '.', '!']

def __init__(self, *args, **kwargs):
"""
Creates a new Markdown instance.
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions markdown/extensions/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes me wonder if ESCAPED_CHARS should be a set. Then it will always only contain one of each item and extensions don't need to check before appending. Just an idea.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea. That would be even better :).

md.ESCAPED_CHARS.append('|')
md.parser.blockprocessors.add('table',
TableProcessor(md.parser),
'<hashheader')
Expand Down
15 changes: 15 additions & 0 deletions tests/extensions/extra/tables.html
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,19 @@ <h2>Table Tests</h2>
<td><code>\</code></td>
</tr>
</tbody>
</table>
<p>Test escaped pipes</p>
<table>
<thead>
<tr>
<th>Column1</th>
<th>Column 2</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>|</code> |</td>
<td>Pipes are okay in code and escaped. |</td>
</tr>
</tbody>
</table>
6 changes: 6 additions & 0 deletions tests/extensions/extra/tables.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,9 @@ Odd backticks | Even backticks
Escapes | More Escapes
------- | ------
`` `\`` | `\`

Test escaped pipes

Column1 | Column 2
------- | --------
`|` \| | Pipes are okay in code and escaped. \|
12 changes: 12 additions & 0 deletions tests/test_apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)