From 44fddb82c66345ed55999da7f8b035d0ba43128b Mon Sep 17 00:00:00 2001 From: Nik Nyby Date: Wed, 9 Sep 2015 11:42:19 -0400 Subject: [PATCH 1/3] Add tests to make sure code blocks get rendered correctly This makes sure that html in a code block is escaped appropriately. --- django_markwhat/tests.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/django_markwhat/tests.py b/django_markwhat/tests.py index ef3df49..ad660d1 100644 --- a/django_markwhat/tests.py +++ b/django_markwhat/tests.py @@ -37,6 +37,17 @@ class Templates(unittest.TestCase): ## An h2""" + markdown_content_with_html_code = """Paragraph 1 + +## An h2 + +``` + +``` +""" rest_content = """Paragraph 1 Paragraph 2 with a link_ @@ -66,6 +77,18 @@ def test_markdown(self): pattern = re.compile("""

Paragraph 1\s*

\s*

\s*An h2

""") self.assertTrue(pattern.match(rendered)) + @unittest.skipUnless(markdown, 'markdown not installed') + def test_markdown_html_code(self): + t = Template("{% load markup %}{{ markdown_content|markdown }}") + rendered = t.render(Context({ + 'markdown_content': self.markdown_content_with_html_code + })).strip() + pattern = re.compile( + '

Paragraph 1\s*

\s*

\s*An h2

' + + '\s*

\s*<video width="320"' + ) + self.assertTrue(pattern.match(rendered)) + @unittest.skipUnless( markdown and markdown_version >= (2, 1), 'markdown >= 2.1 not installed' @@ -103,6 +126,18 @@ def test_commonmark(self): pattern = re.compile("""

Paragraph 1\s*

\s*

\s*An h2

""") self.assertTrue(pattern.match(rendered)) + @unittest.skipUnless(CommonMark, 'commonmark not installed') + def test_commonmark_html_code(self): + t = Template("{% load markup %}{{ markdown_content|commonmark }}") + rendered = t.render(Context({ + 'markdown_content': self.markdown_content_with_html_code + })).strip() + pattern = re.compile( + '

Paragraph 1\s*

\s*

\s*An h2

' + + '\s*
\s*<video width="320"'
+        )
+        self.assertTrue(pattern.match(rendered))
+
     @unittest.skipUnless(CommonMark, 'commonmark not installed')
     def test_commonmark_empty_str(self):
         t = Template("{% load markup %}{{ markdown_content|commonmark }}")

From c449d41a899881b3d04692d8527500edfdb33863 Mon Sep 17 00:00:00 2001
From: Nik Nyby 
Date: Wed, 9 Sep 2015 13:13:35 -0400
Subject: [PATCH 2/3] Add iframe tests

---
 django_markwhat/tests.py | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/django_markwhat/tests.py b/django_markwhat/tests.py
index ad660d1..c300871 100644
--- a/django_markwhat/tests.py
+++ b/django_markwhat/tests.py
@@ -48,6 +48,16 @@ class Templates(unittest.TestCase):
     
 ```
 """
+
+    markdown_content_with_iframe_code = """Paragraph 1
+
+## An h2
+
+```
+    
+```
+"""
+
     rest_content = """Paragraph 1
 
 Paragraph 2 with a link_
@@ -89,6 +99,19 @@ def test_markdown_html_code(self):
         )
         self.assertTrue(pattern.match(rendered))
 
+    @unittest.skipUnless(markdown, 'markdown not installed')
+    def test_markdown_html_iframe_code(self):
+        t = Template("{% load markup %}{{ markdown_content|markdown }}")
+        rendered = t.render(Context({
+            'markdown_content': self.markdown_content_with_iframe_code
+        })).strip()
+        pattern = re.compile(
+            '

Paragraph 1\s*

\s*

\s*An h2

' + + '\s*

\s*<iframe src="http://example.com">' + + '</iframe>' + ) + self.assertTrue(pattern.match(rendered)) + @unittest.skipUnless( markdown and markdown_version >= (2, 1), 'markdown >= 2.1 not installed' @@ -138,6 +161,20 @@ def test_commonmark_html_code(self): ) self.assertTrue(pattern.match(rendered)) + @unittest.skipUnless(CommonMark, 'commonmark not installed') + def test_commonmark_html_iframe_code(self): + t = Template("{% load markup %}{{ markdown_content|commonmark }}") + rendered = t.render(Context({ + 'markdown_content': self.markdown_content_with_iframe_code + })).strip() + pattern = re.compile( + '

Paragraph 1\s*

\s*

\s*An h2

' + + '\s*
\s*<iframe ' +
+            'src="http://example.com">' +
+            '</iframe>'
+        )
+        self.assertTrue(pattern.match(rendered))
+
     @unittest.skipUnless(CommonMark, 'commonmark not installed')
     def test_commonmark_empty_str(self):
         t = Template("{% load markup %}{{ markdown_content|commonmark }}")

From c03072d386ac5806c8bddcc030f4f276be6508db Mon Sep 17 00:00:00 2001
From: Nik Nyby 
Date: Thu, 10 Sep 2015 11:02:18 -0400
Subject: [PATCH 3/3] update changelog

---
 ChangeLog.rst | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/ChangeLog.rst b/ChangeLog.rst
index 8514206..3cc9026 100644
--- a/ChangeLog.rst
+++ b/ChangeLog.rst
@@ -1,3 +1,11 @@
+1.5
+==============
+----
+
+* Added tests for rendering code blocks.
+
+
+
 1.4 2015-04-26
 ==============
 ----