diff options
author | Waylan Limberg <waylan.limberg@icloud.com> | 2019-03-08 16:28:07 -0500 |
---|---|---|
committer | Waylan Limberg <waylan.limberg@icloud.com> | 2019-03-08 16:28:07 -0500 |
commit | 194b7d316ac4eaacfa4588023489fbafc038d7ca (patch) | |
tree | 01b218f8b15b4a5312ba00e532a9545e21e9371a | |
parent | 71854c0c4415a456cc42e2d6aa27b279ec55f915 (diff) | |
download | python-markdown-194b7d316ac4eaacfa4588023489fbafc038d7ca.tar.gz |
More tests.
-rw-r--r-- | markdown/blockprocessors.py | 1 | ||||
-rw-r--r-- | tests/test_syntax/blocks/test_html_blocks.py | 228 |
2 files changed, 228 insertions, 1 deletions
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): '<p><code><em>code span</em></code></p>' ) + def test_raw_empty(self): + self.assertMarkdownRenders( + '<p></p>', + '<p></p>' + ) + + def test_raw_empty_space(self): + self.assertMarkdownRenders( + '<p> </p>', + '<p> </p>' + ) + + def test_raw_empty_newline(self): + self.assertMarkdownRenders( + '<p>\n</p>', + '<p>\n</p>' + ) + + def test_raw_empty_blank_line(self): + self.assertMarkdownRenders( + '<p>\n\n</p>', + '<p>\n\n</p>' + ) + 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( + """ + <div> + <p> + <span>*text*</span> + </p> + </div> + """ + ), + self.dedent( + """ + <div> + <p> + <span>*text*</span> + </p> + </div> + """ + ) + ) + + def test_raw_nested_inline_with_blank_lines(self): + self.assertMarkdownRenders( + self.dedent( + """ + <div> + + <p> + + <span>*text*</span> + + </p> + + </div> + """ + ), + self.dedent( + """ + <div> + + <p> + + <span>*text*</span> + + </p> + + </div> + """ + ) + ) + + # 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 `</div>`. + def test_raw_p_no_end_tag(self): + self.assertMarkdownRenders( + '<p>*text*', + '<p>*text*' + ) + + # TODO: fix this. See comment on previous test method. + def test_raw_multiple_p_no_end_tag(self): + self.assertMarkdownRenders( + self.dedent( + """ + <p>*text*' + + <p>more *text* + """ + ), + self.dedent( + """ + <p>*text*' + + <p>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( + """ + <p>*raw text*' + + Still part of *raw* text. + """ + ), + self.dedent( + """ + <p>*raw text*' + + Still part of *raw* text. + """ + ) + ) + + def test_raw_nested_p_no_end_tag(self): + self.assertMarkdownRenders( + '<div><p>*text*</div>', + '<div><p>*text*</div>' + ) + + def test_raw_open_bracket_only(self): + self.assertMarkdownRenders( + '<', + '<p><</p>' + ) + + def test_raw_open_bracket_followed_by_space(self): + self.assertMarkdownRenders( + '< foo', + '<p>< foo</p>' + ) + + def test_raw_missing_close_bracket(self): + self.assertMarkdownRenders( + '<foo', + '<p><foo</p>' + ) + + def test_raw_attributes(self): + self.assertMarkdownRenders( + '<p id="foo", class="bar baz", style="margin: 15px; line-height: 1.5; text-align: center;">text</p>', + '<p id="foo", class="bar baz", style="margin: 15px; line-height: 1.5; text-align: center;">text</p>' + ) + + def test_raw_attributes_nested(self): + self.assertMarkdownRenders( + self.dedent( + """ + <div id="foo, class="bar", style="background: #ffe7e8; border: 2px solid #e66465;"> + <p id="baz", style="margin: 15px; line-height: 1.5; text-align: center;">text</p> + </div> + """ + ), + self.dedent( + """ + <div id="foo, class="bar", style="background: #ffe7e8; border: 2px solid #e66465;"> + <p id="baz", style="margin: 15px; line-height: 1.5; text-align: center;">text</p> + </div> + """ + ) + ) + + def test_raw_comment_one_line(self): + self.assertMarkdownRenders( + '<!-- *foo* -->', + '<!-- *foo* -->' + ) + + # TODO: Confirm this is correct + def test_raw_comment_one_line_followed_by_text(self): + self.assertMarkdownRenders( + '<!-- *foo* -->*bar*', + '<!-- *foo* -->*bar*' + ) + + def test_raw_multiline_comment(self): + self.assertMarkdownRenders( + self.dedent( + """ + <!-- + *foo* + --> + """ + ), + self.dedent( + """ + <!-- + *foo* + --> + """ + ) + ) + + def test_raw_comment_with_blank_lines(self): + self.assertMarkdownRenders( + self.dedent( + """ + <!-- + + *foo* + + --> + """ + ), + self.dedent( + """ + <!-- + + *foo* + + --> + """ + ) + ) + + # TODO: processing instruction, declaration, CDATA... |