def test_convert_markdown(self): """ Ensure that basic Markdown -> HTML and TOC works. """ html, toc, meta = build.convert_markdown(dedent(""" page_title: custom title # Heading 1 This is some text. # Heading 2 And some more text. """)) expected_html = dedent(""" <h1 id="heading-1">Heading 1</h1> <p>This is some text.</p> <h1 id="heading-2">Heading 2</h1> <p>And some more text.</p> """) expected_toc = dedent(""" Heading 1 - #heading-1 Heading 2 - #heading-2 """) expected_meta = {'page_title': ['custom title']} self.assertEqual(html.strip(), expected_html) self.assertEqual(str(toc).strip(), expected_toc) self.assertEqual(meta, expected_meta)
def test_markdown_table_extension(self): """ Ensure that the table extension is supported. """ html, toc, meta = build.convert_markdown(dedent(""" First Header | Second Header -------------- | -------------- Content Cell 1 | Content Cell 2 Content Cell 3 | Content Cell 4 """)) expected_html = dedent(""" <table> <thead> <tr> <th>First Header</th> <th>Second Header</th> </tr> </thead> <tbody> <tr> <td>Content Cell 1</td> <td>Content Cell 2</td> </tr> <tr> <td>Content Cell 3</td> <td>Content Cell 4</td> </tr> </tbody> </table> """) self.assertEqual(html.strip(), expected_html)
def test_markdown_table_extension(self): """ Ensure that the table extension is supported. """ html, toc, meta = build.convert_markdown( dedent(""" First Header | Second Header -------------- | -------------- Content Cell 1 | Content Cell 2 Content Cell 3 | Content Cell 4 """)) expected_html = dedent(""" <table> <thead> <tr> <th>First Header</th> <th>Second Header</th> </tr> </thead> <tbody> <tr> <td>Content Cell 1</td> <td>Content Cell 2</td> </tr> <tr> <td>Content Cell 3</td> <td>Content Cell 4</td> </tr> </tbody> </table> """) self.assertEqual(html.strip(), expected_html)
def test_convert_markdown(self): """ Ensure that basic Markdown -> HTML and TOC works. """ html, toc, meta = build.convert_markdown( dedent(""" page_title: custom title # Heading 1 This is some text. # Heading 2 And some more text. """)) expected_html = dedent(""" <h1 id="heading-1">Heading 1</h1> <p>This is some text.</p> <h1 id="heading-2">Heading 2</h1> <p>And some more text.</p> """) expected_toc = dedent(""" Heading 1 - #heading-1 Heading 2 - #heading-2 """) expected_meta = {'page_title': ['custom title']} self.assertEqual(html.strip(), expected_html) self.assertEqual(str(toc).strip(), expected_toc) self.assertEqual(meta, expected_meta)
def test_markdown_fenced_code_extension(self): """ Ensure that the fenced code extension is supported. """ html, toc, meta = build.convert_markdown(dedent(""" ``` print 'foo' ``` """)) expected_html = dedent(""" <pre><code>print 'foo'\n</code></pre> """) self.assertEqual(html.strip(), expected_html)
def test_markdown_fenced_code_extension(self): """ Ensure that the fenced code extension is supported. """ html, toc, meta = build.convert_markdown( dedent(""" ``` print 'foo' ``` """)) expected_html = dedent(""" <pre><code>print 'foo'\n</code></pre> """) self.assertEqual(html.strip(), expected_html)
def test_ignore_external_link(self): md_text = 'An [external link](http://example.com/external.md).' expected = '<p>An <a href="http://example.com/external.md">external link</a>.</p>' html, toc, meta = build.convert_markdown(md_text) html = build.post_process_html(html) self.assertEqual(html.strip(), expected.strip())
def test_convert_internal_link_with_anchor(self): md_text = 'An [internal link](internal.md#section1.1) to another document.' expected = '<p>An <a href="internal/#section1.1">internal link</a> to another document.</p>' html, toc, meta = build.convert_markdown(md_text) html = build.post_process_html(html) self.assertEqual(html.strip(), expected.strip())
def test_convert_internal_link_differing_directory(self): md_text = 'An [internal link](../internal.md) to another document.' expected = '<p>An <a href="../internal/">internal link</a> to another document.</p>' html, toc, meta = build.convert_markdown(md_text) html = build.post_process_html(html) self.assertEqual(html.strip(), expected.strip())
def test_convert_multiple_internal_links(self): md_text = '[First link](first.md) [second link](second.md).' expected = '<p><a href="first/">First link</a> <a href="second/">second link</a>.</p>' html, toc, meta = build.convert_markdown(md_text) html = build.post_process_html(html) self.assertEqual(html.strip(), expected.strip())