aboutsummaryrefslogtreecommitdiffstats
path: root/markdown
diff options
context:
space:
mode:
authorIsaac Muse <faceless.shop@gmail.com>2017-01-20 16:16:52 -0700
committerWaylan Limberg <waylan.limberg@icloud.com>2017-01-20 18:16:52 -0500
commit4a3d1a6bc0cb49d8a472380614b53fdd300e7512 (patch)
tree1cfe266d3f780096673e2604cdce375c35cac9bd /markdown
parentc70b2c4154d9b6e46f282c1f212c52e9fbfa5a07 (diff)
downloadmarkdown-4a3d1a6bc0cb49d8a472380614b53fdd300e7512.tar.gz
markdown-4a3d1a6bc0cb49d8a472380614b53fdd300e7512.tar.bz2
markdown-4a3d1a6bc0cb49d8a472380614b53fdd300e7512.zip
Better inline code escaping (#533)
This aims to escape code in a more expected fashion. This handles when backticks are escaped and when the escapes before backticks are escaped.
Diffstat (limited to 'markdown')
-rw-r--r--markdown/inlinepatterns.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/markdown/inlinepatterns.py b/markdown/inlinepatterns.py
index 67bc2a8..37c9afa 100644
--- a/markdown/inlinepatterns.py
+++ b/markdown/inlinepatterns.py
@@ -103,7 +103,7 @@ BRK = (
NOIMG = r'(?<!\!)'
# `e=f()` or ``e=f("`")``
-BACKTICK_RE = r'(?<!\\)(`+)(.+?)(?<!`)\2(?!`)'
+BACKTICK_RE = r'(?:(?<!\\)((?:\\{2})+)(?=`+)|(?<!\\)(`+)(.+?)(?<!`)\3(?!`))'
# \<
ESCAPE_RE = r'\\(.)'
@@ -302,12 +302,16 @@ class BacktickPattern(Pattern):
""" Return a `<code>` 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):