the footnote extra expects to only parse one document over the Markup's lifetime, and writes the footnotes to the bottom of every page that is rendered (again assuming only one) with links back to the reference having one parser for the entire app, naturally, introduced ever-increasing footnote links and every footnote on the site showing up on every page. this was not intended in some light testing, doing this per-request has a nominal effect on performance
22 lines
926 B
Python
22 lines
926 B
Python
"""Miscellaneous helper functions and whatnot."""
|
|
import markdown
|
|
from flask import current_app as app
|
|
|
|
|
|
def get_meta_str(md, key):
|
|
"""Provide the page's (parsed in Markup obj md) metadata for the specified key, or '' if unset."""
|
|
return " ".join(md.Meta.get(key)) if md.Meta.get(key) else ""
|
|
|
|
|
|
def init_md():
|
|
"""Initialize the Markdown parser.
|
|
|
|
This used to done at the app level in __init__, but extensions like footnotes apparently
|
|
assume the parser to only live for the length of parsing one document, and create double
|
|
footnote ref links if the one parser sees the same document multiple times.
|
|
"""
|
|
# initialize markdown parser from config, but include
|
|
# extensions our app depends on, like the meta extension
|
|
return markdown.Markdown(extensions=app.config['MARKDOWN_EXTENSIONS'] + ['meta'],
|
|
extension_configs=app.config['MARKDOWN_EXTENSION_CONFIGS'])
|