aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWaylan Limberg <waylan@gmail.com>2011-06-28 16:14:59 -0400
committerWaylan Limberg <waylan@gmail.com>2011-06-28 16:16:55 -0400
commit8761cd1780a7cec6012354f79303f3ea488df7d9 (patch)
tree5626a0628ec156dbbf087dce98e6f1cf2e854906
parent9b26d2b5e567f0c18ed9ef88ee4f3d82bb4092cf (diff)
downloadmarkdown-8761cd1780a7cec6012354f79303f3ea488df7d9.tar.gz
markdown-8761cd1780a7cec6012354f79303f3ea488df7d9.tar.bz2
markdown-8761cd1780a7cec6012354f79303f3ea488df7d9.zip
Fixed #28. Inline raw html is now enclosed in p tags. This used to work. Somehow we stopped checking for a single inline html element when swapping back in raw html. Added a test. Also patched a weird (invalid) comment test. Seeing the input is not really a valid html comment - it doesn't matter what we do with it. I suppose we test it to make sure it doesn't break the parser. Actual output is not so important. As a side note, this has exposed a preexisting (unrelated) bug with the extra extension's handling of raw html. That test is failing following this fix.
-rw-r--r--markdown/postprocessors.py13
-rw-r--r--tests/misc/html.html1
-rw-r--r--tests/misc/html.txt2
-rw-r--r--tests/misc/more_comments.html3
4 files changed, 16 insertions, 3 deletions
diff --git a/markdown/postprocessors.py b/markdown/postprocessors.py
index cd90eb8..8985fb8 100644
--- a/markdown/postprocessors.py
+++ b/markdown/postprocessors.py
@@ -8,6 +8,7 @@ processing.
"""
+import re
import util
import odict
@@ -55,7 +56,7 @@ class RawHtmlPostprocessor(Postprocessor):
html = ''
else:
html = self.markdown.html_replacement_text
- if safe or not self.markdown.safeMode:
+ if self.isblocklevel(html) and (safe or not self.markdown.safeMode):
text = text.replace("<p>%s</p>" %
(self.markdown.htmlStash.get_placeholder(i)),
html + "\n")
@@ -78,6 +79,16 @@ class RawHtmlPostprocessor(Postprocessor):
return html.replace('"', '&quot;')
+ def isblocklevel(self, html):
+ m = re.match(r'^\<\/?([^ ]+)', html)
+ if m:
+ if m.group(1).startswith(('!', '?', '@', '%')):
+ # Comment, php etc...
+ return True
+ return util.isBlockLevel(m.group(1))
+ return False
+
+
class AndSubstitutePostprocessor(Postprocessor):
""" Restore valid entities """
def __init__(self):
diff --git a/tests/misc/html.html b/tests/misc/html.html
index dd4e4e8..c72bb81 100644
--- a/tests/misc/html.html
+++ b/tests/misc/html.html
@@ -12,6 +12,7 @@ Html with various attributes.
<p>And of course <script>blah</script>.</p>
<p><a href="script&gt;stuff&lt;/script">this <script>link</a></p>
<p>Some funky <x\]> inline stuff with markdown escaping syntax.</p>
+<p><img scr="foo.png" title="Only one inline element on a line." /></p>
<p>And now a line with only an opening bracket:</p>
<p>&lt;</p>
<p>And one with other stuff but no closing bracket:</p>
diff --git a/tests/misc/html.txt b/tests/misc/html.txt
index b51d30b..dfee68d 100644
--- a/tests/misc/html.txt
+++ b/tests/misc/html.txt
@@ -17,6 +17,8 @@ And of course <script>blah</script>.
Some funky <x\]> inline stuff with markdown escaping syntax.
+<img scr="foo.png" title="Only one inline element on a line." />
+
And now a line with only an opening bracket:
<
diff --git a/tests/misc/more_comments.html b/tests/misc/more_comments.html
index 97074d5..99f5781 100644
--- a/tests/misc/more_comments.html
+++ b/tests/misc/more_comments.html
@@ -2,6 +2,5 @@
<!asd@asdfd.com>
-<asd!@asdfd.com>
-
+<p><asd!@asdfd.com></p>
<p>Test</p> \ No newline at end of file