From 425fde141f17973aea0a3a85e44632fe18737996 Mon Sep 17 00:00:00 2001 From: Mike Dirolf Date: Thu, 12 Jan 2012 23:20:45 -0500 Subject: attempt at a fix for issue w/ MD links inside of html tagish stuff with safe mode on. --- markdown/postprocessors.py | 7 +++++-- tests/html4_safe/link.html | 1 + tests/html4_safe/link.txt | 1 + tests/html4_safe/test.cfg | 3 +++ 4 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 tests/html4_safe/link.html create mode 100644 tests/html4_safe/link.txt create mode 100644 tests/html4_safe/test.cfg diff --git a/markdown/postprocessors.py b/markdown/postprocessors.py index b21a569..962728b 100644 --- a/markdown/postprocessors.py +++ b/markdown/postprocessors.py @@ -49,7 +49,6 @@ class RawHtmlPostprocessor(Postprocessor): """ Iterate over html stash and restore "safe" html. """ for i in range(self.markdown.htmlStash.html_counter): html, safe = self.markdown.htmlStash.rawHtmlBlocks[i] - html = self.unescape(html) if self.markdown.safeMode and not safe: if str(self.markdown.safeMode).lower() == 'escape': html = self.escape(html) @@ -61,6 +60,7 @@ class RawHtmlPostprocessor(Postprocessor): text = text.replace("

%s

" % (self.markdown.htmlStash.get_placeholder(i)), html + "\n") + html = self.unescape(html) text = text.replace(self.markdown.htmlStash.get_placeholder(i), html) return text @@ -69,7 +69,10 @@ class RawHtmlPostprocessor(Postprocessor): """ Unescape any markdown escaped text within inline html. """ for k, v in self.markdown.treeprocessors['inline'].stashed_nodes.items(): ph = util.INLINE_PLACEHOLDER % k - html = html.replace(ph, '\%s' % v) + try: + html = html.replace(ph, '%s' % util.etree.tostring(v)) + except: + html = html.replace(ph, '\%s' % v) return html def escape(self, html): diff --git a/tests/html4_safe/link.html b/tests/html4_safe/link.html new file mode 100644 index 0000000..642f4be --- /dev/null +++ b/tests/html4_safe/link.html @@ -0,0 +1 @@ +

<here gmail.com is a link>

\ No newline at end of file diff --git a/tests/html4_safe/link.txt b/tests/html4_safe/link.txt new file mode 100644 index 0000000..28331a7 --- /dev/null +++ b/tests/html4_safe/link.txt @@ -0,0 +1 @@ + diff --git a/tests/html4_safe/test.cfg b/tests/html4_safe/test.cfg new file mode 100644 index 0000000..66f7bf0 --- /dev/null +++ b/tests/html4_safe/test.cfg @@ -0,0 +1,3 @@ +[DEFAULT] +output_format=html4 +safe_mode=escape -- cgit v1.2.3