2020-09-18 19:43:10 +02:00
|
|
|
from app import app
|
|
|
|
from markupsafe import Markup
|
|
|
|
from markdown import markdown
|
2021-02-20 15:39:52 +01:00
|
|
|
from markdown.extensions.codehilite import CodeHiliteExtension
|
|
|
|
from markdown.extensions.footnotes import FootnoteExtension
|
|
|
|
from markdown.extensions.toc import TocExtension
|
|
|
|
|
2021-02-20 17:17:33 +01:00
|
|
|
from app.utils.markdown_extensions.pclinks import PCLinkExtension
|
2021-02-23 12:00:34 +01:00
|
|
|
from app.utils.markdown_extensions.escape_html import EscapeHtml
|
2021-02-20 17:17:33 +01:00
|
|
|
|
2020-09-18 19:43:10 +02:00
|
|
|
|
|
|
|
@app.template_filter('md')
|
|
|
|
def md(text):
|
|
|
|
"""
|
|
|
|
Converts markdown to html5
|
|
|
|
"""
|
2021-02-20 15:39:52 +01:00
|
|
|
|
|
|
|
options = 0
|
|
|
|
extensions = [
|
|
|
|
# 'admonition',
|
|
|
|
'fenced_code',
|
|
|
|
'nl2br',
|
|
|
|
'sane_lists',
|
|
|
|
'tables',
|
|
|
|
CodeHiliteExtension(linenums=True, use_pygments=True),
|
2021-02-23 12:00:34 +01:00
|
|
|
EscapeHtml(),
|
2021-02-20 15:39:52 +01:00
|
|
|
FootnoteExtension(UNIQUE_IDS=True),
|
|
|
|
TocExtension(baselevel=2),
|
2021-02-20 17:17:33 +01:00
|
|
|
PCLinkExtension(),
|
2021-02-20 15:39:52 +01:00
|
|
|
]
|
|
|
|
|
2021-02-23 12:00:34 +01:00
|
|
|
out = markdown(text, options=options, extensions=extensions)
|
2021-02-20 15:39:52 +01:00
|
|
|
|
|
|
|
return Markup(out)
|