diff options
author | Waylan Limberg <waylan@gmail.com> | 2011-08-17 11:45:54 -0400 |
---|---|---|
committer | Waylan Limberg <waylan@gmail.com> | 2011-08-17 11:45:54 -0400 |
commit | e5b2813bbf02710c7deb148896085a3dac4828dc (patch) | |
tree | 80dfc847569c45737ba22cf3c3dc20e1dae13be8 /markdown/inlinepatterns.py | |
parent | 39e9e08e783df4054b6448f4285ca31c4db24a18 (diff) | |
download | markdown-e5b2813bbf02710c7deb148896085a3dac4828dc.tar.gz markdown-e5b2813bbf02710c7deb148896085a3dac4828dc.tar.bz2 markdown-e5b2813bbf02710c7deb148896085a3dac4828dc.zip |
Fixed #39. Refactored escaping so that it only escapes a predifined set of chars (the set defined by JG in the syntax rules). All other backslashes are passed through unaltered by the parser. If extensions want to add to the escapable chars, they can append to the list at markdown.ESCAPED_CHARS.
Diffstat (limited to 'markdown/inlinepatterns.py')
-rw-r--r-- | markdown/inlinepatterns.py | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/markdown/inlinepatterns.py b/markdown/inlinepatterns.py index 35f0335..1e05e00 100644 --- a/markdown/inlinepatterns.py +++ b/markdown/inlinepatterns.py @@ -59,7 +59,7 @@ def build_inlinepatterns(md_instance, **kwargs): """ Build the default set of inline patterns for Markdown. """ inlinePatterns = odict.OrderedDict() inlinePatterns["backtick"] = BacktickPattern(BACKTICK_RE) - inlinePatterns["escape"] = SimpleTextPattern(ESCAPE_RE) + inlinePatterns["escape"] = EscapePattern(ESCAPE_RE, md_instance) inlinePatterns["reference"] = ReferencePattern(REFERENCE_RE, md_instance) inlinePatterns["link"] = LinkPattern(LINK_RE, md_instance) inlinePatterns["image_link"] = ImagePattern(IMAGE_LINK_RE, md_instance) @@ -197,8 +197,6 @@ class Pattern: return util.INLINE_PLACEHOLDER_RE.sub(get_stash, text) -BasePattern = Pattern # for backward compatibility - class SimpleTextPattern(Pattern): """ Return a simple text of group(2) of a Pattern. """ def handleMatch(self, m): @@ -207,6 +205,18 @@ class SimpleTextPattern(Pattern): return None return text + +class EscapePattern(Pattern): + """ Return an escaped character. """ + + def handleMatch(self, m): + char = m.group(2) + if char in self.markdown.ESCAPED_CHARS: + return '%s%s%s' % (util.STX, ord(char), util.ETX) + else: + return '\\%s' % char + + class SimpleTagPattern(Pattern): """ Return element of type `tag` with a text attribute of group(3) |