Snippets are unofficial and unmaintained.
This is an archived view of user-submitted snippets. Despite being hosted on the Flask site, they are not official. No Flask maintainer has curated or checked the snippets for security, correctness, or design.
The Markdown language is very useful if you don't know the html language In this snippet, I want to show you how to include this language in your Flask App
easy_install markdown
The code of your Flask application: demo.py
# We import the markdown library
import markdown
from flask import Flask
from flask import render_template
from flask import Markup
app = Flask(__name__)
@app.route('/')
def index():
content = """
Chapter
=======
Section
-------
* Item 1
* Item 2
"""
content = Markup(markdown.markdown(content))
return render_template('index.html', **locals())
app.run(debug=True)
The Jinja template file: templates/index.html
<html>
<head>
<title>Markdown Snippet</title>
</head>
<body>
{{ content }}
</body>
</html>
This snippet by Stephane Wirtel can be used freely for anything you like. Consider it public domain.
Comments
Flask-Markdown by Sean Lynch on 2011-07-21 @ 02:12
There is also an extension [Flask-Markdown](http://packages.python.org/Flask-Markdown/) that adds some Jinja2 template filters and provides an easier way to write Markdown extensions.
Oops by Sean Lynch on 2011-07-21 @ 02:14
I thought comments supported Markdown, guess I was wrong :)
Comment by Sean Lynch on 2011-07-21 @ 02:18
Just read on another snippet I should have used Creole, oops.
Or as filter by Олег Васильевич on 2012-11-07 @ 21:09
@app.template_filter('markdown') def markdown_filter(data): from flask import Markup from markdown import markdown return Markup(markdown(data))
use in template: {{ comment.content|markdown }}
Flask-Misaka by David Baumgold on 2013-03-06 @ 05:34
You can also use the Flask-Misaka library to render Markdown: https://flask-misaka.readthedocs.org It's faster and better-integrated than the markdown library.