From 194b7d316ac4eaacfa4588023489fbafc038d7ca Mon Sep 17 00:00:00 2001 From: Waylan Limberg Date: Fri, 8 Mar 2019 16:28:07 -0500 Subject: More tests. --- markdown/blockprocessors.py | 1 + tests/test_syntax/blocks/test_html_blocks.py | 228 ++++++++++++++++++++++++++- 2 files changed, 228 insertions(+), 1 deletion(-) diff --git a/markdown/blockprocessors.py b/markdown/blockprocessors.py index 63e8b4d..7c1b9fe 100644 --- a/markdown/blockprocessors.py +++ b/markdown/blockprocessors.py @@ -290,6 +290,7 @@ class RawHtmlProcessor(BlockProcessor): parser.feed(blocks.pop(0) + '\n\n') if not parser.inraw: break + parser.close() # Insert Markdown back into blocks with raw HTML extracted. parts = ''.join(parser.cleandoc).split('\n\n') parts.reverse() diff --git a/tests/test_syntax/blocks/test_html_blocks.py b/tests/test_syntax/blocks/test_html_blocks.py index e25d76d..8c600a4 100644 --- a/tests/test_syntax/blocks/test_html_blocks.py +++ b/tests/test_syntax/blocks/test_html_blocks.py @@ -20,7 +20,6 @@ Copyright 2004 Manfred Stienstra (the original version) License: BSD (see LICENSE.md for details). """ -import unittest from markdown.test_tools import TestCase @@ -69,6 +68,30 @@ class TestHTMLBlocks(TestCase): '

<em>code span</em>

' ) + def test_raw_empty(self): + self.assertMarkdownRenders( + '

', + '

' + ) + + def test_raw_empty_space(self): + self.assertMarkdownRenders( + '

', + '

' + ) + + def test_raw_empty_newline(self): + self.assertMarkdownRenders( + '

\n

', + '

\n

' + ) + + def test_raw_empty_blank_line(self): + self.assertMarkdownRenders( + '

\n\n

', + '

\n\n

' + ) + def test_multiline_raw(self): self.assertMarkdownRenders( self.dedent( @@ -308,3 +331,206 @@ class TestHTMLBlocks(TestCase): """ ) ) + + def test_raw_nested_inline(self): + self.assertMarkdownRenders( + self.dedent( + """ +
+

+ *text* +

+
+ """ + ), + self.dedent( + """ +
+

+ *text* +

+
+ """ + ) + ) + + def test_raw_nested_inline_with_blank_lines(self): + self.assertMarkdownRenders( + self.dedent( + """ +
+ +

+ + *text* + +

+ +
+ """ + ), + self.dedent( + """ +
+ +

+ + *text* + +

+ +
+ """ + ) + ) + + # TODO: fix this. Presumably as the parser finishes things up in the `handle_endtag` + # method and as there is no end tag here, that code never gets run. Is there a way + # to retrieve the unprocessed source text from HTMLParser? May have to read the source. + # The `test_raw_nested_p_no_end_tag` below works because of the closing ``. + def test_raw_p_no_end_tag(self): + self.assertMarkdownRenders( + '

*text*', + '

*text*' + ) + + # TODO: fix this. See comment on previous test method. + def test_raw_multiple_p_no_end_tag(self): + self.assertMarkdownRenders( + self.dedent( + """ +

*text*' + +

more *text* + """ + ), + self.dedent( + """ +

*text*' + +

more *text* + """ + ) + ) + + # TODO: fix this. See comment on previous test method. + def test_raw_p_no_end_tag_followed_by_blank_line(self): + self.assertMarkdownRenders( + self.dedent( + """ +

*raw text*' + + Still part of *raw* text. + """ + ), + self.dedent( + """ +

*raw text*' + + Still part of *raw* text. + """ + ) + ) + + def test_raw_nested_p_no_end_tag(self): + self.assertMarkdownRenders( + '

*text*

', + '

*text*

' + ) + + def test_raw_open_bracket_only(self): + self.assertMarkdownRenders( + '<', + '

<

' + ) + + def test_raw_open_bracket_followed_by_space(self): + self.assertMarkdownRenders( + '< foo', + '

< foo

' + ) + + def test_raw_missing_close_bracket(self): + self.assertMarkdownRenders( + '<foo

' + ) + + def test_raw_attributes(self): + self.assertMarkdownRenders( + '

text

', + '

text

' + ) + + def test_raw_attributes_nested(self): + self.assertMarkdownRenders( + self.dedent( + """ +
+

text

+
+ """ + ), + self.dedent( + """ +
+

text

+
+ """ + ) + ) + + def test_raw_comment_one_line(self): + self.assertMarkdownRenders( + '', + '' + ) + + # TODO: Confirm this is correct + def test_raw_comment_one_line_followed_by_text(self): + self.assertMarkdownRenders( + '*bar*', + '*bar*' + ) + + def test_raw_multiline_comment(self): + self.assertMarkdownRenders( + self.dedent( + """ + + """ + ), + self.dedent( + """ + + """ + ) + ) + + def test_raw_comment_with_blank_lines(self): + self.assertMarkdownRenders( + self.dedent( + """ + + """ + ), + self.dedent( + """ + + """ + ) + ) + + # TODO: processing instruction, declaration, CDATA... -- cgit v1.2.1