Flask-SimpleMDE - a Flask extension for SimpleMDE¶
Flask-SimpleMDE is an extension to Flask that helps integrate SimpleMDE Markdown Editor to your Flask application.
Quick Start¶
- Installation
pip install Flask-SimpleMDE
- Configuration
from flask import Flask, render_template from flask_simplemde import SimpleMDE app = Flask(__name__) app.config['SIMPLEMDE_JS_IIFE'] = True app.config['SIMPLEMDE_USE_CDN'] = True SimpleMDE(app) @app.route('/') def hello(): return render_template('hello.html') if __name__ == '__main__': app.run(debug=True)
- In
templates/hello.html
:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Flask-SimpleMDE example</title> {{ simplemde.css }} {{ simplemde.js }} </head> <body> <textarea> Some Markdown Text Here </textarea> {{ simplemde.load }} </body> </html>
- Profit!
How It Works¶
Once registered, this extension provides a template variable called
simplemde
, it has:
a property named
css
that will be rendered as HTML<link>
tag to the SimpleMDE stylesheet either from free CDN or be served from a bundled blueprint, also calledsimplemde
.{{ simplemde.css }}
a property named
js
that will be rendered as HTML<script>
tag to the SimpleMDE javascript either from free CDN or be served from a bundled blueprint, also calledsimplemde
.{{ simplemde.js }}
a property named
load
that will be rendered as HTML<script>
tag with javascript code that loads the SimpleMDE Markdown Editor with the first<textarea>
tag.{{ simplemde.load }}
a method named
load_id
that when called with a string, will be rendered as HTML<script>
tag with javascript code that loads the SimpleMDE Markdown Editor with the<textarea>
tag which has the specifiedid
attribute<textarea id="editor"></textarea> ... {{ simplemde.load_id("editor") }}
License¶
BSD New, see LICENSE for details.
Links¶
Configuration¶
Option | Description |
---|---|
SIMPLEMDE_JS_IIFE |
If True , the SimpleMDE loading javascript
will be in IIFE style. If False , a
simpler declaration will be used |
SIMPLEMDE_USE_CDN |
If True , SimpleMDE’s css and javascript files
will be served from CDN. If False , local
copies of these files will be served. Default value
is True |
SimpleMDE Version¶
The bundled version of SimpleMDE is v1.10.1
API¶
Flask-SimpleMDE - a Flask extension for SimpleMDE Markdown Editor
-
class
flask_simplemde.
SimpleMDE
(app=None)[source]¶ Flask-SimpleMDE extension
provides links to SimpleMDE’s static assets.
-
css
¶ property that will be rendered as
<link>
tags for css
-
init_app
(app)[source]¶ create and register a blueprint with the Flask application.
Parameters: app – Flask application instance
-
js
¶ property that will be rendered as
<style>
tags for js
-
load
¶ property that will be rendered as javascript loading code
-