This commit is contained in:
xenia 2019-06-01 00:34:50 -04:00
parent f3c98dad27
commit 549e15add0
3 changed files with 9 additions and 4 deletions

3
.gitignore vendored
View File

@ -6,6 +6,7 @@ __pycache__
*.egg-info
.env
.ycm_extra_conf.py
postgres/
.direnv
.envrc
.mypy_cache/
.vimrc

View File

@ -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)

View File

@ -5,6 +5,6 @@
{% endblock %}
{% block content %}
<h2>{{ article_title }}</h2>
<h1>{{ article_title }}</h1>
{{ article_content }}
{% endblock %}