aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--markdown/inlinepatterns.py25
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