Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Remove nested pre in code blocks

  • Loading branch information...
commit 8e9716ebd9c9b731966e5a92508786c80db1dbfb 1 parent eeba62d
@rsenk330 authored
View
4 pypeline/filters/markdown.py
@@ -5,9 +5,9 @@
class SyntaxRenderer(m.HtmlRenderer):
def block_code(self, text, lang):
if lang:
- return '\n<pre><code lang="{0}">{1}</code></pre>\n'.format(lang, saxutils.escape(text.strip()))
+ return '\n<pre lang="{0}">{1}</pre>\n'.format(lang, saxutils.escape(text.strip()))
else:
- return '\n<pre><code>{0}</code></pre>\n'.format(saxutils.escape(text.strip()))
+ return '\n<pre>{0}</pre>\n'.format(saxutils.escape(text.strip()))
def markdown(context={}):
"""Renders HTML from Makrdown text.
View
6 pypeline/filters/mention.py
@@ -39,13 +39,13 @@ def __call__(self, content):
"""Runs the filter and replaces all `@mention`'s with links"""
fragment = fromstring(content)
- for index, el in enumerate(fragment):
+ for index, el in enumerate(fragment.findall(".//*")):
text = el.text
- if '@' not in text: continue
+ if text and '@' not in text: continue
if self._should_ignore(el): continue
- fragment[index] = self._add_mention_links(el)
+ el.getparent().replace(el, self._add_mention_links(el))
return tostring(fragment)
View
4 pypeline/filters/syntax_highlighter.py
@@ -28,11 +28,11 @@ def __init__(self, context={}):
def __call__(self, content):
fragment = fromstring(content)
- for el in fragment.findall("..//code"):
+ for el in fragment.findall("..//pre"):
lang = el.attrib.get('lang', None)
if lang is None: continue
- highlighted = self._highlight(lang, tostring(el))
+ highlighted = self._highlight(lang, el.text)
el.clear()
el.append(fromstring(highlighted))
View
4 pypeline/filters/tests/markdown_tests.py
@@ -27,10 +27,10 @@ def setUp(self):
def test_block_code_lang_set(self):
"""Test to make sure that the proper code block is rendered (with lang)"""
- expected = '\n<pre><code lang="python">code sample</code></pre>\n'
+ expected = '\n<pre lang="python">code sample</pre>\n'
self.assertEqual(self.renderer.block_code("code sample", "python"), expected)
def test_block_code_lang_not_set(self):
"""Test to make sure that the proper code block is rendered (without lang)"""
- expected = '\n<pre><code>code sample</code></pre>\n'
+ expected = '\n<pre>code sample</pre>\n'
self.assertEqual(self.renderer.block_code("code sample", None), expected)
View
15 pypeline/filters/tests/syntax_highlighter_tests.py
@@ -35,16 +35,15 @@ def test():
highlighted = fromstring(self.filter._highlight('invalid', html))
self.assertTrue(highlighted.findall(".//pre"))
- self.assertFalse(highlighted.findall(".//code"))
def test_render_valid_lang(self):
"""Tests to make sure syntax is rendered with a valid lang"""
html = """\
-<code lang="python">
+<pre lang="python">
def test():
for i in range(10):
print(i)
-</code>
+</pre>
"""
highlighted = fromstring(self.filter(html))
@@ -52,33 +51,31 @@ def test():
self.assertTrue(highlighted.findall("..//div"))
self.assertTrue(highlighted.findall("..//pre"))
self.assertTrue(highlighted.findall("..//span"))
- self.assertTrue(highlighted.findall("..//code"))
def test_render_invalid_lang(self):
"""Tests to make sure syntax is rendered with an invalid lang"""
html = """\
-<code lang="invalid">
+<pre lang="invalid">
def test():
for i in range(10):
print(i)
-</code>
+</pre>
"""
highlighted = fromstring(self.filter(html))
self.assertEqual(len(highlighted.findall("..//div[@class='source']")), 1)
self.assertTrue(highlighted.findall("..//div"))
self.assertTrue(highlighted.findall("..//pre"))
- self.assertTrue(highlighted.findall("..//code"))
self.assertFalse(highlighted.findall("..//span"))
def test_render_html_escape(self):
"""Make sure tags are escaped"""
html = """\
-<code lang="html">
+<pre lang="html">
<script type="text/html">
alert("Hello world!");
</script>
-</code>
+</pre>
"""
highlighted = fromstring(self.filter(html))
Please sign in to comment.
Something went wrong with that request. Please try again.