class TestToc: def setup_method(self): self.markdown = Markdown() self.markdown.use("toc") def test_render_toc(self): content = "# Foo\n## Foobar\n## Foofooz\n# Bar\n" result = self.markdown(content) assert '<h1 id="foo">Foo</h1>' in result toc = self.markdown.renderer.render_toc() assert '<ul>\n<li><a href="#foo">Foo</a></li>' in toc assert '<ul>\n<li><a href="#foobar">Foobar</a></li>' in toc def test_render_toc_exceeding_maxdepth(self): content = "#### Foobar\n" self.markdown(content) toc = self.markdown.renderer.render_toc() assert '<li><a href="#foobar">Foobar</a></li>' in toc content = "# Foo\n#### Foobar\n" self.markdown(content) toc = self.markdown.renderer.render_toc() assert '<li><a href="#foo">Foo</a></li>' in toc assert '<li><a href="#foobar">Foobar</a></li>' not in toc def test_render_toc_replace_tags(self): from marko.ext.toc import Toc markdown = Markdown(extensions=[Toc("<div>", "</div>")]) content = "#### Foobar\n" markdown(content) toc = markdown.renderer.render_toc() assert "<div>\n" in toc assert "</div>\n" in toc
class TestFootnote: def setup_method(self): self.markdown = Markdown() self.markdown.use("footnote") def test_footnote(self): result = self.markdown("this is a footnote[^1].\n\n[^1]: foo\n") assert '<sup class="footnote-ref"' in result assert 'foo<a href="#fnref-1" class="footnote">↩</a>' in result def test_non_footnote(self): result = self.markdown("foo[^1]") assert result.rstrip() == "<p>foo[^1]</p>"
class TestPangu: def setup_method(self): self.markdown = Markdown() self.markdown.use("pangu") def test_render_pangu(self): content = "中国2018年" result = self.markdown(content) assert ( result == '<p>中国<span class="pangu"></span>2018<span class="pangu"></span>年</p>\n' ) def test_chinese_punctuations(self): content = "你好:中国。" result = self.markdown(content) assert result == "<p>你好:中国。</p>\n"
align = ' align="{}"'.format(element.align) return "<{tag}{align}>{children}</{tag}>\n".format( tag=tag, children=self.render_children(element), align=align ) def render_url(self, element): return self.render_link(element) class GFM(object): elements = [ elements.Paragraph, elements.ListItem, elements.Strikethrough, elements.Url, elements.Table, elements.TableRow, elements.TableCell, ] renderer_mixins = [GFMRendererMixin] GFMExtension = helpers._Deprecated(GFM) gfm = Markdown() gfm.use(GFM) def make_extension(): return GFM()