diff options
author | Waylan Limberg <waylan@gmail.com> | 2012-01-18 23:56:56 -0500 |
---|---|---|
committer | Waylan Limberg <waylan@gmail.com> | 2012-01-18 23:56:56 -0500 |
commit | 481e50700e269f9a56337cd9fabc3b5251958d10 (patch) | |
tree | 269237d32923c6e5b86d3c6ebdf0cd4d1ea957e0 | |
parent | 01f4b8cdcf37e3e17e50dfbb51b49472f4b5dc95 (diff) | |
download | markdown-481e50700e269f9a56337cd9fabc3b5251958d10.tar.gz markdown-481e50700e269f9a56337cd9fabc3b5251958d10.tar.bz2 markdown-481e50700e269f9a56337cd9fabc3b5251958d10.zip |
Fixed #59. Raw HTML parsing is no longer slow.
Replaced the unescape method I carlessly threw in the RawHtmlProcessor.
Unfortunetly, this reintroduces the bug just fixed in commit
425fde141f17973aea0a3a85e44632fe18737996 Sigh!
-rw-r--r-- | markdown/inlinepatterns.py | 15 | ||||
-rw-r--r-- | markdown/postprocessors.py | 12 |
2 files changed, 13 insertions, 14 deletions
diff --git a/markdown/inlinepatterns.py b/markdown/inlinepatterns.py index 1829348..2a33816 100644 --- a/markdown/inlinepatterns.py +++ b/markdown/inlinepatterns.py @@ -268,11 +268,22 @@ class DoubleTagPattern(SimpleTagPattern): class HtmlPattern(Pattern): """ Store raw inline html and return a placeholder. """ def handleMatch (self, m): - rawhtml = m.group(2) - inline = True + rawhtml = self.unescape(m.group(2)) place_holder = self.markdown.htmlStash.store(rawhtml) return place_holder + def unescape(self, text): + """ Return unescaped text given text with an inline placeholder. """ + try: + stash = self.markdown.treeprocessors['inline'].stashed_nodes + except KeyError: + return text + def get_stash(m): + id = m.group(1) + if id in stash: + return '\%s' % stash.get(id) + return util.INLINE_PLACEHOLDER_RE.sub(get_stash, text) + class LinkPattern(Pattern): """ Return a link element from the given match. """ diff --git a/markdown/postprocessors.py b/markdown/postprocessors.py index 962728b..672953a 100644 --- a/markdown/postprocessors.py +++ b/markdown/postprocessors.py @@ -60,21 +60,10 @@ class RawHtmlPostprocessor(Postprocessor): text = text.replace("<p>%s</p>" % (self.markdown.htmlStash.get_placeholder(i)), html + "\n") - html = self.unescape(html) text = text.replace(self.markdown.htmlStash.get_placeholder(i), html) return text - def unescape(self, html): - """ Unescape any markdown escaped text within inline html. """ - for k, v in self.markdown.treeprocessors['inline'].stashed_nodes.items(): - ph = util.INLINE_PLACEHOLDER % k - try: - html = html.replace(ph, '%s' % util.etree.tostring(v)) - except: - html = html.replace(ph, '\%s' % v) - return html - def escape(self, html): """ Basic html escaping """ html = html.replace('&', '&') @@ -82,7 +71,6 @@ class RawHtmlPostprocessor(Postprocessor): html = html.replace('>', '>') return html.replace('"', '"') - def isblocklevel(self, html): m = re.match(r'^\<\/?([^ ]+)', html) if m: |