Flask-Markdown adds support for Markdown to your Flask application. There is little to no documentation for it, but it works just the same as markdown would normally.
All source code can be found at Github
Install the extension with one of the following commands:
$ easy_install Flask-Markdown
or alternatively if you have pip installed:
$ pip install Flask-Markdown
To use you must construct a Markdown with your Flask instance.
from flaskext.markdown import Markdown
Markdown(app)
Then in your template
{% filter markdown %}
Your Markdown
=============
{% endfilter %}
You can also do
{{ mkd|markdown }}
Optionally, you can keep a reference to the Markdown instance and use that to register custom extensions by calling Markdown.register_extension() or decorating the extension class with Markdown.extend()
Simple wrapper class for Markdown objects, any options that are available for markdown may be passed as keyword arguments like so:
md = Markdown(app,
extensions=['footnotes'],
extension_configs={'footnotes': ('PLACE_MARKER','~~~~~~~~')},
safe_mode=True,
output_format='html4',
)
You can then call register_extension() to load custom extensions into the Markdown instance or use the extend() decorator
Parameters: |
|
---|
Decorator for registering macros
You must either force the decorated class to be imported or define it in the same file you instantiate Markdown. To register a simple extension you could do:
from flaskext.markdown import Extension, Markdown
from preprocessors import SimplePreprocessor
markdown_instance = Markdown(app)
@markdown_instance.make_extension()
class SimpleExtension(Extension):
def extendMarkdown(self, md, md_globals):
md.preprocessors.add('prover_block',
SimplePreprocessor(md),
'_begin')
md.registerExtension(self)
Parameters: |
|
---|
This will register an extension class with self._instance. You may pass any additional configs required for your extension
It is best to call this when starting your Flask app, ie.:
from .mdx_simpl import SimpleExtension
md = Markdown(app)
md.register_extension(SimpleExtension)
Any additional configuration arguments can be added to configs and will be passed through to the extension you are registering
Parameters: |
|
---|