Add TOC
This commit is contained in:
parent
f3c98dad27
commit
549e15add0
|
@ -6,6 +6,7 @@ __pycache__
|
|||
*.egg-info
|
||||
.env
|
||||
.ycm_extra_conf.py
|
||||
postgres/
|
||||
.direnv
|
||||
.envrc
|
||||
.mypy_cache/
|
||||
.vimrc
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -5,6 +5,6 @@
|
|||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h2>{{ article_title }}</h2>
|
||||
<h1>{{ article_title }}</h1>
|
||||
{{ article_content }}
|
||||
{% endblock %}
|
||||
|
|
Loading…
Reference in New Issue