diff options
author | Waylan Limberg <waylan@gmail.com> | 2012-11-01 09:48:27 -0400 |
---|---|---|
committer | Waylan Limberg <waylan@gmail.com> | 2012-11-01 09:48:27 -0400 |
commit | 6bf582515a6b346b23100818f529b96b932f9b97 (patch) | |
tree | e4924703183e419f8ac969fdea73e5866d030d37 | |
parent | f02f0626049352c2520fcad66c90e1f92a05539d (diff) | |
download | markdown-6bf582515a6b346b23100818f529b96b932f9b97.tar.gz markdown-6bf582515a6b346b23100818f529b96b932f9b97.tar.bz2 markdown-6bf582515a6b346b23100818f529b96b932f9b97.zip |
A better fix for #155. Unescaping inline placholders now returns the text only of an Element - rather than the html which just gets html escaped in the output anyway.
-rw-r--r-- | markdown/inlinepatterns.py | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/markdown/inlinepatterns.py b/markdown/inlinepatterns.py index b3caeb0..b07598f 100644 --- a/markdown/inlinepatterns.py +++ b/markdown/inlinepatterns.py @@ -189,14 +189,27 @@ class Pattern: stash = self.markdown.treeprocessors['inline'].stashed_nodes except KeyError: return text + def itertext(el): + ' Reimplement Element.itertext for older python versions ' + tag = el.tag + if not isinstance(tag, basestring) and tag is not None: + return + if el.text: + yield el.text + for e in el: + for s in itertext(e): + yield s + if e.tail: + yield e.tail def get_stash(m): id = m.group(1) if id in stash: - text = stash.get(id) - if isinstance(text, basestring): - return text + value = stash.get(id) + if isinstance(value, basestring): + return value else: - return self.markdown.serializer(text) + # An etree Element - return text content only + return ''.join(itertext(value)) return util.INLINE_PLACEHOLDER_RE.sub(get_stash, text) @@ -286,7 +299,7 @@ class HtmlPattern(Pattern): value = stash.get(id) if value is not None: try: - return self.markdown.serializer(value) + return self.markdown.serializer(text) except: return '\%s' % value @@ -420,7 +433,7 @@ class ImageReferencePattern(ReferencePattern): el.set("src", self.sanitize_url(href)) if title: el.set("title", title) - el.set("alt", text) + el.set("alt", self.unescape(text)) return el |