diff --git a/markdown/inlinepatterns.py b/markdown/inlinepatterns.py index 67bc2a80d..37c9aface 100644 --- a/markdown/inlinepatterns.py +++ b/markdown/inlinepatterns.py @@ -103,7 +103,7 @@ def build_inlinepatterns(md_instance, **kwargs): NOIMG = r'(?` element containing the matching text. """ def __init__(self, pattern): Pattern.__init__(self, pattern) - self.tag = "code" + self.ESCAPED_BSLASH = '%s%s%s' % (util.STX, ord('\\'), util.ETX) + self.tag = 'code' def handleMatch(self, m): - el = util.etree.Element(self.tag) - el.text = util.AtomicString(m.group(3).strip()) - return el + if m.group(4): + el = util.etree.Element(self.tag) + el.text = util.AtomicString(m.group(4).strip()) + return el + else: + return m.group(2).replace('\\\\', self.ESCAPED_BSLASH) class DoubleTagPattern(SimpleTagPattern): diff --git a/tests/extensions/extra/tables.html b/tests/extensions/extra/tables.html index b81582c78..2418c9834 100644 --- a/tests/extensions/extra/tables.html +++ b/tests/extensions/extra/tables.html @@ -356,4 +356,23 @@

Table Tests

| Column1 | Column2 | | ------- || ------- | | row1 | row1 | -| row2 | row2 |

\ No newline at end of file +| row2 | row2 |

+

Test escaped code in Table

+ + + + + + + + + + + + + + + + + +
Should not be codeShould be code
`Not code`\code
\`Not code\`\\code
\ No newline at end of file diff --git a/tests/extensions/extra/tables.txt b/tests/extensions/extra/tables.txt index d5bd6eadf..d766224fd 100644 --- a/tests/extensions/extra/tables.txt +++ b/tests/extensions/extra/tables.txt @@ -121,3 +121,10 @@ Escaped pipes in format row should not be a table | ------- \|| ------- | | row1 | row1 | | row2 | row2 | + +Test escaped code in Table + +Should not be code | Should be code +------------------ | -------------- +\`Not code\` | \\`code` +\\\`Not code\\\` | \\\\`code` diff --git a/tests/misc/backtick-escape.html b/tests/misc/backtick-escape.html index 07f5115d5..da305414c 100644 --- a/tests/misc/backtick-escape.html +++ b/tests/misc/backtick-escape.html @@ -1,3 +1,4 @@ -

\`This should not be in code.\` -`This also should not be in code.` +

`This should not be in code.` +\This should be in code.\\ +\`This should not be in code.\` `And finally this should not be in code.`

\ No newline at end of file diff --git a/tests/misc/backtick-escape.txt b/tests/misc/backtick-escape.txt index b4d80b2fc..c0194638e 100644 --- a/tests/misc/backtick-escape.txt +++ b/tests/misc/backtick-escape.txt @@ -1,3 +1,4 @@ -\\`This should not be in code.\\` -\`This also should not be in code.\` +\`This should not be in code.\` +\\`This should be in code.\\` +\\\`This should not be in code.\\\` \`And finally this should not be in code.`