From fd16e7d1b4090b8466997b98ce84e5a9d9ebc4d0 Mon Sep 17 00:00:00 2001 From: INOPIAE Date: Wed, 19 Feb 2020 06:15:25 +0100 Subject: [PATCH] upd: allow markdown text in motion content Markdown is used for formatting the motion text. --- README.md | 6 ++++++ motion.py | 9 +++++++++ requirements.txt | 1 + templates/index.html | 2 ++ templates/motion.html | 2 +- 5 files changed, 19 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3b33b93..01406ef 100644 --- a/README.md +++ b/README.md @@ -14,3 +14,9 @@ LANG=C.UTF-8 FLASK_DEBUG=1 FLASK_APP=motion.py flask run ``` The database schema is automatically installed when the table "schema_version" does not exist and the application is started. + +# Usage + +Within the motion content markdown can be used for formatting e.g. +* To add a line break add two lines +* to enter a link use `[text](https//domain.tld/link)` diff --git a/motion.py b/motion.py index eb04eff..f6ddf13 100644 --- a/motion.py +++ b/motion.py @@ -4,6 +4,8 @@ from flask import render_template, redirect from flask import request import postgresql import filters +from flaskext.markdown import Markdown +from markdown.extensions import Extension def get_db(): db = getattr(g, '_database', None) @@ -15,6 +17,13 @@ def get_db(): app = Flask(__name__) app.register_blueprint(filters.blueprint) +class EscapeHtml(Extension): + def extendMarkdown(self, md, md_globals): + del md.preprocessors['html_block'] + del md.inlinePatterns['html'] + +md = Markdown(app, extensions=[EscapeHtml()]) + # Load config app.config.from_pyfile('config.py') diff --git a/requirements.txt b/requirements.txt index e3bed75..7bfcb1f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,3 +5,4 @@ Jinja2==2.10 MarkupSafe==1.0 py-postgresql==1.2.1 Werkzeug==0.12.2 +Flask-Markdown==0.3 diff --git a/templates/index.html b/templates/index.html index 4ff3a44..125dc7c 100644 --- a/templates/index.html +++ b/templates/index.html @@ -29,6 +29,8 @@ User: {{g.user}}

+ Editing note: Markdown is used formatting.
+ To add a line break add two lines, to enter a link use [text](https//domain.tld/link)
diff --git a/templates/motion.html b/templates/motion.html index eac27bd..87b3e41 100644 --- a/templates/motion.html +++ b/templates/motion.html @@ -17,7 +17,7 @@ {%- endif %}
-

{{motion.content}}

+

{{motion.content|markdown}}

{%- if motion.yes or motion.no or motion.abstain %}

{%- for vote in ['yes', 'no', 'abstain'] %} -- 2.39.2