def test_disallowed_raw_html_extension_653(): """ Test case 653: All other HTML tags are left untouched. """ # Arrange source_markdown = """<strong> <title> <style> <em> <blockquote> <xmp> is disallowed. <XMP> is also disallowed. </blockquote>""" expected_tokens = [ "[para:]", "[raw-html:a]", "[raw-html:bab]", "[raw-html:c2c]", "[end-para]", ] expected_gfm = """ """ # Act & Assert act_and_assert(source_markdown, expected_gfm, expected_tokens)
def test_fenced_code_blocks_112(): """ Test case 112: (part a) An info string can be provided after the opening code fence. """ # Arrange source_markdown = """```ruby def foo(x) return 3 end ```""" expected_tokens = [ "[fcode-block(1,1):`:3:ruby:::::]", "[text(2,1):def foo(x)\n return 3\nend:]", "[end-fcode-block::3:False]", ] expected_gfm = """<pre><code class="language-ruby">def foo(x) return 3 end </code></pre>""" # Act & Assert act_and_assert(source_markdown, expected_gfm, expected_tokens)
def test_emphasis_428(): """ Test case 428: (part 2) When the lengths of the interior closing and opening delimiter runs are both multiples of 3, though, they can match to create emphasis: """ # Arrange source_markdown = """*foo [*bar*](/url)*""" expected_tokens = [ "[para(1,1):]", "[emphasis(1,1):1:*]", "[text(1,2):foo :]", "[link(1,6):inline:/url:::::*bar*:False::::]", "[emphasis(1,7):1:*]", "[text(1,8):bar:]", "[end-emphasis(1,11)::]", "[end-link::]", "[end-emphasis(1,19)::]", "[end-para:::True]", ] expected_gfm = """<p><em>foo <a href="/url"><em>bar</em></a></em></p>""" # Act & Assert act_and_assert(source_markdown, expected_gfm, expected_tokens)
def test_raw_html_646(): """ Test case 646: Not comments: """ # Arrange source_markdown = """foo <!--> foo --> foo <!-- foo--->""" expected_tokens = [ "[para(1,1):]", "[text(1,1):foo \a<\a<\a!--\a>\a>\a foo --\a>\a>\a:]", "[end-para:::True]", "[BLANK(2,1):]", "[para(3,1):]", "[text(3,1):foo \a<\a<\a!-- foo---\a>\a>\a:]", "[end-para:::True]", ] expected_gfm = """<p>foo <!--> foo --></p> <p>foo <!-- foo---></p>""" # Act & Assert act_and_assert(source_markdown, expected_gfm, expected_tokens)
def test_front_matter_03(): """ Everything between the start and end is parsed, but not as part of HTML output. """ # Arrange source_markdown = """--- Title: my document --- --- """ expected_tokens = [ "[front-matter(1,1):---:---:['Title: my document']:{'title': 'my document'}]", "[tbreak(4,1):-::---]", "[BLANK(5,1):]", ] expected_gfm = """<hr />""" # Act & Assert act_and_assert(source_markdown, expected_gfm, expected_tokens, config_map=config_map)
def test_image_link_600(): """ Test case 600: If you just want a literal ! followed by bracketed text, you can backslash-escape the opening [: """ # Arrange source_markdown = """!\\[foo] [foo]: /url "title" """ expected_tokens = [ "[para(1,1):]", "[text(1,1):!\\\b[foo:]", "[text(1,7):]:]", "[end-para:::True]", "[BLANK(2,1):]", '[link-ref-def(3,1):True::foo:: :/url:: :title:"title":]', "[BLANK(4,1):]", ] expected_gfm = """<p>![foo]</p>""" # Act & Assert act_and_assert(source_markdown, expected_gfm, expected_tokens)
def test_image_link_592b(): """ Test case 592a: variation of 592 with extra space and text after """ # Arrange source_markdown = """![foo][]\atext [foo]: /url "title" """.replace("\a", " ") expected_tokens = [ "[para(1,1):]", "[image(1,1):collapsed:/url:title:foo::::foo:False::::]", "[text(1,9): text:]", "[end-para:::True]", "[BLANK(2,1):]", '[link-ref-def(3,1):True::foo:: :/url:: :title:"title":]', "[BLANK(4,1):]", ] expected_gfm = """<p><img src="/url" alt="foo" title="title" /> text</p>""" # Act & Assert act_and_assert(source_markdown, expected_gfm, expected_tokens)
def test_indented_code_blocks_085(): """ Test case 085: And indented code can occur immediately before and after other kinds of blocks: """ # Arrange source_markdown = """# Heading foo Heading ------ foo ----""" expected_tokens = [ "[atx(1,1):1:0:]", "[text(1,3):Heading: ]", "[end-atx::]", "[icode-block(2,5): :]", "[text(2,5):foo:]", "[end-icode-block:::False]", "[setext(4,1):-:6::(3,1)]", "[text(3,1):Heading:]", "[end-setext::]", "[icode-block(5,5): :]", "[text(5,5):foo:]", "[end-icode-block:::False]", "[tbreak(6,1):-::----]", ] expected_gfm = """<h1>Heading</h1> <pre><code>foo </code></pre> <h2>Heading</h2> <pre><code>foo </code></pre> <hr />""" # Act & Assert act_and_assert(source_markdown, expected_gfm, expected_tokens)
def test_fenced_code_blocks_extra_08b(): """ Test case extra 08: variation of 8 with close fence and extra tex """ # Arrange source_markdown = """``` abc ``` abc def ```""" expected_tokens = [ "[fcode-block(1,1):`:3::::::]", "[text(2,1):abc:]", "[end-fcode-block::3:False]", "[BLANK(4,1):]", "[para(5,1):]", "[text(5,1):abc:]", "[end-para:::True]", "[BLANK(6,1):]", "[para(7,1):]", "[text(7,1):def:]", "[end-para:::False]", "[fcode-block(8,1):`:3::::::]", "[end-fcode-block:::True]", ] expected_gfm = """<pre><code>abc </code></pre> <p>abc</p> <p>def</p> <pre><code></code></pre>""" # Act & Assert act_and_assert(source_markdown, expected_gfm, expected_tokens)
def test_fenced_code_blocks_extra_03x(): """ Test case extra 03: variation of 1 where list already opened but no new list item NOTE: Small change to output to remove newline at pre/code at end. """ # Arrange source_markdown = """- ``` some text some other text ``` """ expected_tokens = [ "[ulist(1,1):-::2:: ]", "[fcode-block(1,3):`:3::::::]", "[text(2,3):some text:]", "[end-fcode-block:::True]", "[end-ulist:::True]", "[para(3,1):]", "[text(3,1):some other text:]", "[end-para:::False]", "[fcode-block(4,1):`:3::::::]", "[text(5,1)::]", "[end-fcode-block:::True]", ] expected_gfm = """<ul> <li> <pre><code>some text </code></pre> </li> </ul> <p>some other text</p> <pre><code></code></pre>""" # Act & Assert act_and_assert(source_markdown, expected_gfm, expected_tokens)
def test_paragraph_series_m_hb_ol_nl_i3_ol_nl_i2_hb(): """ Test case: Ordered list newline indent of 3 ordered list newline indent of 2 html block """ # Arrange source_markdown = """1. 1. <script> foo </script> """ expected_tokens = [ "[olist(1,1):.:1:3:]", "[BLANK(1,3):]", "[olist(2,4):.:1:6: ]", "[BLANK(2,6):]", "[end-olist:::True]", "[end-olist:::True]", "[html-block(3,1)]", "[text(3,3):<script>\nfoo\n</script>: ]", "[end-html-block:::False]", "[BLANK(6,1):]", ] expected_gfm = """<ol> <li> <ol> <li></li> </ol> </li> </ol> <script> foo </script>""" # Act & Assert act_and_assert(source_markdown, expected_gfm, expected_tokens)
def test_paragraph_series_m_hb_ol_t_nl_i4_hb(): """ Test case: Ordered list text newline indent of 4 html block was: test_list_blocks_256kab """ # Arrange source_markdown = """1. abc <script> foo </script> """ expected_tokens = [ "[olist(1,1):.:1:4:: ]", "[para(1,5):]", "[text(1,5):abc:]", "[end-para:::False]", "[html-block(2,5)]", "[text(2,5):<script>:]", "[end-html-block:::True]", "[end-olist:::True]", "[para(3,1):\n]", "[text(3,1):foo\n::\n]", "[raw-html(4,1):/script]", "[end-para:::True]", "[BLANK(5,1):]", ] expected_gfm = """<ol> <li>abc <script> </li> </ol> <p>foo </script></p>""" # Act & Assert act_and_assert(source_markdown, expected_gfm, expected_tokens)
def test_paragraph_series_m_ha_ol_t_nl_ol_t_nl_i3_ha_t(): """ Test case: Ordered list text newline ordered list text new line indent of 3 atx heading text """ # Arrange source_markdown = """1. abc 1. abc # foo """ expected_tokens = [ "[olist(1,1):.:1:3:: \n]", "[para(1,4):]", "[text(1,4):abc:]", "[end-para:::True]", "[olist(2,4):.:1:6: ]", "[para(2,7):]", "[text(2,7):abc:]", "[end-para:::True]", "[end-olist:::True]", "[atx(3,4):1:0:]", "[text(3,6):foo: ]", "[end-atx::]", "[BLANK(4,1):]", "[end-olist:::True]", ] expected_gfm = """<ol> <li>abc <ol> <li>abc</li> </ol> <h1>foo</h1> </li> </ol>""" # Act & Assert act_and_assert(source_markdown, expected_gfm, expected_tokens)
def test_paragraph_series_m_fb_ol_ol_t_nl_all_i6_fb(): """ Test case: Ordered list x2 text newline fenced block """ # Arrange source_markdown = """1. 1. abc ``` foo ``` """ expected_tokens = [ "[olist(1,1):.:1:3:]", "[olist(1,4):.:1:6: : \n \n \n]", "[para(1,7):]", "[text(1,7):abc:]", "[end-para:::False]", "[fcode-block(2,7):`:3::::::]", "[text(3,7):foo:]", "[end-fcode-block::3:False]", "[BLANK(5,1):]", "[end-olist:::True]", "[end-olist:::True]", ] expected_gfm = """<ol> <li> <ol> <li>abc <pre><code>foo </code></pre> </li> </ol> </li> </ol>""" # Act & Assert act_and_assert(source_markdown, expected_gfm, expected_tokens)
def test_thematic_breaks_025(): """ Test case 025: However, no other characters may occur in the line: """ # Arrange source_markdown = """_ _ _ _ a a------ ---a---""" expected_tokens = [ "[para(1,1):]", "[text(1,1):_:]", "[text(1,2): :]", "[text(1,3):_:]", "[text(1,4): :]", "[text(1,5):_:]", "[text(1,6): :]", "[text(1,7):_:]", "[text(1,8): a:]", "[end-para:::True]", "[BLANK(2,1):]", "[para(3,1):]", "[text(3,1):a------:]", "[end-para:::True]", "[BLANK(4,1):]", "[para(5,1):]", "[text(5,1):---a---:]", "[end-para:::True]", ] expected_gfm = """<p>_ _ _ _ a</p> <p>a------</p> <p>---a---</p>""" # Act & Assert act_and_assert(source_markdown, expected_gfm, expected_tokens)
def test_setext_headings_062(): """ Test case 062: (part a) The setext heading underline cannot be a lazy continuation line in a list item or block quote: """ # Arrange source_markdown = """> Foo ---""" expected_tokens = [ "[block-quote(1,1)::> ]", "[para(1,3):]", "[text(1,3):Foo:]", "[end-para:::True]", "[end-block-quote:::True]", "[tbreak(2,1):-::---]", ] expected_gfm = """<blockquote> <p>Foo</p> </blockquote> <hr />""" # Act & Assert act_and_assert(source_markdown, expected_gfm, expected_tokens)
def test_setext_headings_061(): """ Test case 061: Since indicators of block structure take precedence over indicators of inline structure, the following are setext headings: """ # Arrange source_markdown = """`Foo ---- ` <a title="a lot --- of dashes"/>""" expected_tokens = [ "[setext(2,1):-:4::(1,1)]", "[text(1,1):`Foo:]", "[end-setext::]", "[para(3,1):]", "[text(3,1):`:]", "[end-para:::True]", "[BLANK(4,1):]", "[setext(6,1):-:3::(5,1)]", '[text(5,1):\a<\a<\aa title=\a"\a"\aa lot:]', "[end-setext::]", "[para(7,1):]", '[text(7,1):of dashes\a"\a"\a/\a>\a>\a:]', "[end-para:::True]", ] expected_gfm = """<h2>`Foo</h2> <p>`</p> <h2><a title="a lot</h2> <p>of dashes"/></p>""" # Act & Assert act_and_assert(source_markdown, expected_gfm, expected_tokens)
def test_paragraph_series_m_fb_ol_nl_i3_ol_nl_i2_fb(): """ Test case: Ordered list newline indent of 3 ordered list newline indent of 2 fenced block """ # Arrange source_markdown = """1. 1. ``` foo ``` """ expected_tokens = [ "[olist(1,1):.:1:3:]", "[BLANK(1,3):]", "[olist(2,4):.:1:6: ]", "[BLANK(2,6):]", "[end-olist:::True]", "[end-olist:::True]", "[fcode-block(3,3):`:3::::: :]", "[text(4,1):foo:]", "[end-fcode-block::3:False]", "[BLANK(6,1):]", ] expected_gfm = """<ol> <li> <ol> <li></li> </ol> </li> </ol> <pre><code>foo </code></pre>""" # Act & Assert act_and_assert(source_markdown, expected_gfm, expected_tokens)
def test_emphasis_479(): """ Test case 479: (part 2) Rule 15 """ # Arrange source_markdown = """*foo __bar *baz bim__ bam*""" expected_tokens = [ "[para(1,1):]", "[emphasis(1,1):1:*]", "[text(1,2):foo :]", "[emphasis(1,6):2:_]", "[text(1,8):bar :]", "[text(1,12):*:]", "[text(1,13):baz bim:]", "[end-emphasis(1,20)::]", "[text(1,22): bam:]", "[end-emphasis(1,26)::]", "[end-para:::True]", ] expected_gfm = """<p><em>foo <strong>bar *baz bim</strong> bam</em></p>""" # Act & Assert act_and_assert(source_markdown, expected_gfm, expected_tokens)
def test_paragraph_series_j_l_t_em_s(): """ Test case: Inline link containing text in label with split emphasis after was: test_paragraph_extra_d3, added title, removed split raw html in label """ # Arrange source_markdown = """a[link](/url)*a\nb*""" expected_tokens = [ "[para(1,1):\n]", "[text(1,1):a:]", "[link(1,2):inline:/url:::::link:False::::]", "[text(1,3):link:]", "[end-link::]", "[emphasis(1,14):1:*]", "[text(1,15):a\nb::\n]", "[end-emphasis(2,2)::]", "[end-para:::True]", ] expected_gfm = """<p>a<a href="/url">link</a><em>a b</em></p>""" # Act & Assert act_and_assert(source_markdown, expected_gfm, expected_tokens)
def test_paragraph_series_j_l_sh_s_t(): """ Test case: Inline image containing space hard line break in label, followed by text was: test_paragraph_extra_h8b """ # Arrange source_markdown = """a[foo \ncom](/uri "title")a""" expected_tokens = [ "[para(1,1):\n]", "[text(1,1):a:]", '[link(1,2):inline:/uri:title::::foo \ncom:False:":: :]', "[text(1,3):foo:]", "[hard-break(1,6): :\n]", "[text(2,1):com:]", "[end-link::]", "[text(2,19):a:]", "[end-para:::True]", ] expected_gfm = """<p>a<a href="/uri" title="title">foo<br /> com</a>a</p>""" # Act & Assert act_and_assert(source_markdown, expected_gfm, expected_tokens)
def test_paragraph_series_j_l_rh_s_t(): """ Test case: Inline link containing split raw html in label was: test_paragraph_extra_c7, changed split text at end to text """ # Arrange source_markdown = """a[li<de\nfg>nk](/url)a""" expected_tokens = [ "[para(1,1):\n]", "[text(1,1):a:]", "[link(1,2):inline:/url:::::li<de\nfg>nk:False::::]", "[text(1,3):li:]", "[raw-html(1,5):de\nfg]", "[text(2,4):nk:]", "[end-link::]", "[text(2,13):a:]", "[end-para:::True]", ] expected_gfm = """<p>a<a href="/url">li<de fg>nk</a>a</p>""" # Act & Assert act_and_assert(source_markdown, expected_gfm, expected_tokens)
def test_thematic_breaks_028(): """ Test case 028: Thematic breaks can interrupt a paragraph: """ # Arrange source_markdown = """Foo *** bar""" expected_tokens = [ "[para(1,1):]", "[text(1,1):Foo:]", "[end-para:::False]", "[tbreak(2,1):*::***]", "[para(3,1):]", "[text(3,1):bar:]", "[end-para:::True]", ] expected_gfm = """<p>Foo</p> <hr /> <p>bar</p>""" # Act & Assert act_and_assert(source_markdown, expected_gfm, expected_tokens)
def test_html_blocks_extrax_03(): """ Test case 03: Pragma at the start and end of the document. """ # Arrange source_markdown = """<!-- pyml --> This is a paragraph still a paragraph and still going. <!-- pyml -->""" expected_tokens = [ "[para(2,1):\n\n]", "[text(2,1):This is a paragraph\nstill a paragraph\nand still going.::\n\n]", "[end-para:::True]", "[pragma:1:<!-- pyml -->;5:<!-- pyml -->]", ] expected_gfm = """<p>This is a paragraph\nstill a paragraph\nand still going.</p>""" # Act & Assert act_and_assert(source_markdown, expected_gfm, expected_tokens, disable_consistency_checks=True)
def test_html_blocks_extrax_05(): """ Test case 05: Single line paragraph with double pragmas to start and end document. """ # Arrange source_markdown = """<!-- pyml --> <!-- pyml --> this is a paragraph <!-- pyml --> <!-- pyml -->""" expected_tokens = [ "[para(3,1):]", "[text(3,1):this is a paragraph:]", "[end-para:::True]", "[pragma:1:<!-- pyml -->;2:<!-- pyml -->;4:<!-- pyml -->;5:<!-- pyml -->]", ] expected_gfm = "<p>this is a paragraph</p>" # Act & Assert act_and_assert(source_markdown, expected_gfm, expected_tokens, disable_consistency_checks=True)
def test_inline_links_497a(): """ Test case 497a: variation of 497 with no inline close and defined reference """ # Arrange source_markdown = """[link]( [link]: /url 'title'""" expected_tokens = [ "[para(1,1):]", "[link(1,1):shortcut:/url:title::::link:False::::]", "[text(1,2):link:]", "[end-link::]", "[text(1,7):(:]", "[end-para:::True]", "[BLANK(2,1): ]", "[link-ref-def(3,1):True::link:: :/url:: :title:'title':]", ] expected_gfm = """<p><a href="/url" title="title">link</a>(</p>""" # Act & Assert act_and_assert(source_markdown, expected_gfm, expected_tokens)
def test_setext_headings_064(): """ Test case 064: (part c) The setext heading underline cannot be a lazy continuation line in a list item or block quote: """ # Arrange source_markdown = """- Foo ---""" expected_tokens = [ "[ulist(1,1):-::2:]", "[para(1,3):]", "[text(1,3):Foo:]", "[end-para:::True]", "[end-ulist:::True]", "[tbreak(2,1):-::---]", ] expected_gfm = """<ul> <li>Foo</li> </ul> <hr />""" # Act & Assert act_and_assert(source_markdown, expected_gfm, expected_tokens)
def test_inline_links_509(): """ Test case 509: A link can contain fragment identifiers and queries: """ # Arrange source_markdown = """[link](#fragment) [link](http://example.com#fragment) [link](http://example.com?foo=3#frag)""" expected_tokens = [ "[para(1,1):]", "[link(1,1):inline:#fragment:::::link:False::::]", "[text(1,2):link:]", "[end-link::]", "[end-para:::True]", "[BLANK(2,1):]", "[para(3,1):]", "[link(3,1):inline:http://example.com#fragment:::::link:False::::]", "[text(3,2):link:]", "[end-link::]", "[end-para:::True]", "[BLANK(4,1):]", "[para(5,1):]", "[link(5,1):inline:http://example.com?foo=3#frag:::::link:False::::]", "[text(5,2):link:]", "[end-link::]", "[end-para:::True]", ] expected_gfm = """<p><a href="#fragment">link</a></p> <p><a href="http://example.com#fragment">link</a></p> <p><a href="http://example.com?foo=3#frag">link</a></p>""" # Act & Assert act_and_assert(source_markdown, expected_gfm, expected_tokens)
def test_setext_headings_064c(): """ Test case 064a: variation of 64 other underline """ # Arrange source_markdown = """- Foo ===""" expected_tokens = [ "[ulist(1,1):-::2:: ]", "[setext(2,3):=:3::(1,3)]", "[text(1,3):Foo:]", "[end-setext::]", "[end-ulist:::True]", ] expected_gfm = """<ul> <li> <h1>Foo</h1> </li> </ul>""" # Act & Assert act_and_assert(source_markdown, expected_gfm, expected_tokens)
def test_paragraph_series_m_hs_ol_nl_i3_ol_t_nl_i2_t_nl_i2_hs(): """ Test case: Ordered list newline indent of 3 ordered list text new line indent of 2 text newline indent of 2 setext heading """ # Arrange source_markdown = """1. 1. def foo --- """ expected_tokens = [ "[olist(1,1):.:1:3:]", "[BLANK(1,3):]", "[olist(2,4):.:1:6: :]", "[para(2,7):\n ]", "[text(2,7):def\nfoo::\n]", "[end-para:::True]", "[end-olist:::True]", "[end-olist:::True]", "[tbreak(4,3):-: :---]", "[BLANK(5,1):]", ] expected_gfm = """<ol> <li> <ol> <li>def foo</li> </ol> </li> </ol> <hr />""" # Act & Assert act_and_assert(source_markdown, expected_gfm, expected_tokens)