aboutsummaryrefslogtreecommitdiffstats
path: root/markdown/postprocessors.py
diff options
context:
space:
mode:
authorWaylan Limberg <waylan@gmail.com>2011-08-17 11:45:54 -0400
committerWaylan Limberg <waylan@gmail.com>2011-08-17 11:45:54 -0400
commite5b2813bbf02710c7deb148896085a3dac4828dc (patch)
tree80dfc847569c45737ba22cf3c3dc20e1dae13be8 /markdown/postprocessors.py
parent39e9e08e783df4054b6448f4285ca31c4db24a18 (diff)
downloadmarkdown-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/postprocessors.py')
-rw-r--r--markdown/postprocessors.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/markdown/postprocessors.py b/markdown/postprocessors.py
index b646027..b21a569 100644
--- a/markdown/postprocessors.py
+++ b/markdown/postprocessors.py
@@ -17,6 +17,7 @@ def build_postprocessors(md_instance, **kwargs):
postprocessors = odict.OrderedDict()
postprocessors["raw_html"] = RawHtmlPostprocessor(md_instance)
postprocessors["amp_substitute"] = AndSubstitutePostprocessor()
+ postprocessors["unescape"] = UnescapePostprocessor()
return postprocessors
@@ -91,9 +92,19 @@ class RawHtmlPostprocessor(Postprocessor):
class AndSubstitutePostprocessor(Postprocessor):
""" Restore valid entities """
- def __init__(self):
- pass
def run(self, text):
text = text.replace(util.AMP_SUBSTITUTE, "&")
return text
+
+
+class UnescapePostprocessor(Postprocessor):
+ """ Restore escaped chars """
+
+ RE = re.compile('%s(\d+)%s' % (util.STX, util.ETX))
+
+ def unescape(self, m):
+ return unichr(int(m.group(1)))
+
+ def run(self, text):
+ return self.RE.sub(self.unescape, text)