Open rsmith-ip opened 8 years ago
Actually it would be wonderful if autodoc could parse markdown from the docstring. It's far more easy and useful then giant Spynx or Doxygen. And parsing markdown is EVERYTHING we need for documentation.
This happens also in 0.11.0
markdown may rendered without any patches in flask-autodoc:
1) create filter for markdown and add it to jinja
[...]
import markdown
from flask import Markup
def md2html(text):
import textwrap
res = Markup(markdown.markdown(
textwrap.dedent(text),
[
'markdown.extensions.codehilite',
'markdown.extensions.nl2br',
'markdown.extensions.extra',
'markdown.extensions.admonition'
], extension_configs={'markdown.extensions.codehilite': {
'noclasses': True,
'pygments_style': 'colorful'
}}))
return res
def create_app():
app = Flask(__name__, static_url_path='/doc')
[...]
app.jinja_env.filters['markdown'] = md2html
[...]
2) use custom templates:
<p>{% autoescape false %}{{doc.docstring|markdown}}{% endautoescape %}</p>
I'm take some css strings from sphinx, but you welcome to create your own.
going off of @stanislavvv 's response, with respect to the original issue if you just want flask-autodoc to format html using tags embedded in docstrings (less all the markdown business) you can use {% autoescape false %}{{doc.docstring|urlize|nl2br}}{% endautoescape %}
in the template file
I'm having the same issue, I'm not using a custom template. Just return auto.html() per the basic examples.
Confirmed with Flask 0.12.2 as well. Without using templates the simplest solution is to roll back Flask to 0.10.
as a workaround you can copy the default template from Flask_Autodoc-0.1.2-py3.4.egg\flask_autodoc\templates\autodoc_default.html to your aplication \templates
afterwards change the line
<p class="docstring">{{doc.docstring|urlize|nl2br}}</p>
to
<p class="docstring">{{doc.docstring|urlize|nl2br|safe}}</p>
when you use auto.html() define the project template to use it
return auto.html(template='autodoc_default.html')
The formatting works fine with Flask 0.10.1 but with 0.11.1 the embedded HTML tags are displayed instead of being processed as HTML.