diff --git a/.gitignore b/.gitignore index 460600a..319c15a 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ __pycache__ *.egg-info .env .ycm_extra_conf.py -postgres/ +.direnv .envrc .mypy_cache/ +.vimrc diff --git a/wikilain/markdown.py b/wikilain/markdown.py index fe57848..43df787 100644 --- a/wikilain/markdown.py +++ b/wikilain/markdown.py @@ -1,6 +1,7 @@ from mistune import Markdown, Renderer, InlineLexer, BlockLexer, BlockGrammar from mistune_contrib.highlight import HighlightMixin from mistune_contrib.math import MathBlockMixin, MathInlineMixin, MathRendererMixin +from mistune_contrib.toc import TocMixin from flask import Markup @@ -16,7 +17,7 @@ class WlBlockLexer(BlockLexer, MathBlockMixin): self.enable_math() -class WlRenderer(Renderer, MathRendererMixin, HighlightMixin): +class WlRenderer(TocMixin, MathRendererMixin, HighlightMixin, Renderer): def __init__(self): super(WlRenderer, self).__init__(escape=True, use_xhtml=True) @@ -29,4 +30,7 @@ markdown = Markdown(renderer=renderer, inline=inline, block=block) __all__ = ["md_render"] def md_render(*args, **kwargs): - return Markup(markdown(*args, **kwargs)) + renderer.reset_toc() + results = markdown(*args, **kwargs) + print(renderer.toc_tree) + return Markup(renderer.render_toc(level=3) + results) diff --git a/wikilain/templates/article.html b/wikilain/templates/article.html index 9da3580..2aaccfe 100644 --- a/wikilain/templates/article.html +++ b/wikilain/templates/article.html @@ -5,6 +5,6 @@ {% endblock %} {% block content %} -

{{ article_title }}

+

{{ article_title }}

{{ article_content }} {% endblock %}