Skip to main content

Implementation of editor.md the markdown editor for Flask and Flask-WTF.

Project description

Implementation of editor.md the markdown editor for Flask and Flask-WTF.

description

It’s combined the https://github.com/pandao/editor.md version 1.5.0 .

usage

from flask_editormd import Editormd
editormd = Editormd()
editormd.init_app(app)

the editormd object is auto inject to the jinja2 template.

Editor

{% extends "editormd/editor.html" %}
{% import "bootstrap/wtf.html" as wtf %}

{% block content -%}

<form method="POST">
    {{ form.hidden_tag() }}

    {{ form.body() }}

    {{ wtf.form_field(form.submit) }}
</form>

{%- endblock content %}


{% block scripts %}
{{ super() }}

{{ editormd.add_editormd(autoHeight=True)}}

{%- endblock scripts %}
from flask import Flask, render_template
from flask_wtf import FlaskForm
from flask_editormd import Editormd
from flask_bootstrap import Bootstrap
from flask_editormd.fields import EditormdField
from wtforms.fields import SubmitField

app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
editormd = Editormd(app)
Bootstrap(app)

class EditormdForm(FlaskForm):
    body = EditormdField()
    submit = SubmitField('Submit')

@app.route('/', methods=['GET', 'POST'])
def index():
    form = EditormdForm()
    if form.validate_on_submit():
        text = form.body.data
        print(text)

    return render_template('index.html', form=form)

Preview

{% extends "editormd/preview.html" %}

{% block content -%}

{{ editormd.add_editormd_previewer(cotnent) }}

{%- endblock content %}
from flask import Flask, render_template
from flask_editormd import Editormd
from flask_bootstrap import Bootstrap

app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
editormd = Editormd(app)
Bootstrap(app)

@app.route('/preview', methods=['GET', 'POST'])
def preview():
    content = """
    ###科学公式 TeX(KaTeX)

$$E=mc^2$$

行内的公式$$E=mc^2$$行内的公式,行内的$$E=mc^2$$公式。

$$\(\sqrt{3x-1}+(1+x)^2\)$$

$$\sin(\alpha)^{\theta}=\sum_{i=0}^{n}(x^i + \cos(f))$$

$$X^2 > Y$$

#####上标和下标

上标:X&lt;sup&gt;2&lt;/sup&gt;

下标:O&lt;sub&gt;2&lt;/sub&gt;
"""
    return render_template('preview.html', content=content)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flask_editormd-0.0.4.tar.gz (1.4 MB view details)

Uploaded Source

File details

Details for the file flask_editormd-0.0.4.tar.gz.

File metadata

  • Download URL: flask_editormd-0.0.4.tar.gz
  • Upload date:
  • Size: 1.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/3.7

File hashes

Hashes for flask_editormd-0.0.4.tar.gz
Algorithm Hash digest
SHA256 631707312d050e6231c0e41df7d89506133bc7d866ae1113912dfb499809e3cb
MD5 7fd16336139c4c1bd5a9a268471025f5
BLAKE2b-256 6a5535b2ddb1929825b30d773abd7e8a88345548d2a51df1646ff20386ffff93

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page