diff options
author | Isaac Muse <faceless.shop@gmail.com> | 2017-01-20 16:16:52 -0700 |
---|---|---|
committer | Waylan Limberg <waylan.limberg@icloud.com> | 2017-01-20 18:16:52 -0500 |
commit | 4a3d1a6bc0cb49d8a472380614b53fdd300e7512 (patch) | |
tree | 1cfe266d3f780096673e2604cdce375c35cac9bd /markdown/inlinepatterns.py | |
parent | c70b2c4154d9b6e46f282c1f212c52e9fbfa5a07 (diff) | |
download | python-markdown-4a3d1a6bc0cb49d8a472380614b53fdd300e7512.tar.gz |
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/inlinepatterns.py')
-rw-r--r-- | markdown/inlinepatterns.py | 14 |
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): |