From 94091131671ef68dfcb1b28bab1c554cf4ff0735 Mon Sep 17 00:00:00 2001 From: Darks Date: Fri, 18 Sep 2020 19:43:10 +0200 Subject: [PATCH] markdown: add markdown rendering --- app/templates/account/user.html | 4 ++-- app/templates/forum/topic.html | 5 +++-- app/utils/filters/__init__.py | 2 +- app/utils/filters/markdown.py | 13 +++++++++++++ 4 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 app/utils/filters/markdown.py diff --git a/app/templates/account/user.html b/app/templates/account/user.html index 96bb349..8bb6ba1 100644 --- a/app/templates/account/user.html +++ b/app/templates/account/user.html @@ -20,7 +20,7 @@
- {{ member.signature }} + {{ member.signature|md }}
Membre depuis le {{ member.register_date|date('%Y-%m-%d') }} @@ -30,7 +30,7 @@

Présentation

- {{ member.bio }} + {{ member.bio|md }}

Groupes

diff --git a/app/templates/forum/topic.html b/app/templates/forum/topic.html index 1602f9c..2aacaac 100644 --- a/app/templates/forum/topic.html +++ b/app/templates/forum/topic.html @@ -13,7 +13,7 @@

{{ t.title }}

- +
{{ widget_user.profile(t.author ) }}{{ t.thread.top_comment.text }}{{ t.thread.top_comment.text|md }}
{{ widget_pagination.paginate(comments, 'forum_topic', t, {'f': t.forum}) }} @@ -34,8 +34,9 @@ | Supprimer
-

{{ c.text }}

+ {{ c.text|md }} {{ widget_attachments.attachments(c) }} + {{ c.author.signature|md }} {% elif loop.index0 != 0 %}
Ce message est le top comment
{% endif %} diff --git a/app/utils/filters/__init__.py b/app/utils/filters/__init__.py index 54f614b..ac08bc7 100644 --- a/app/utils/filters/__init__.py +++ b/app/utils/filters/__init__.py @@ -1,3 +1,3 @@ # Register filters here -from app.utils.filters import date, is_title, pluralize +from app.utils.filters import date, is_title, markdown, pluralize diff --git a/app/utils/filters/markdown.py b/app/utils/filters/markdown.py new file mode 100644 index 0000000..6f0f249 --- /dev/null +++ b/app/utils/filters/markdown.py @@ -0,0 +1,13 @@ +from app import app +from markupsafe import Markup +from markdown import markdown +from werkzeug.utils import escape + +@app.template_filter('md') +def md(text): + """ + Converts markdown to html5 + """ + # Escape html chars because markdown does not + safe = escape(text) + return Markup(markdown(safe))