From d7e7d5dc2c671e2a069ac475b21d5cf4b1150941 Mon Sep 17 00:00:00 2001 From: Evert Date: Wed, 28 Feb 2018 22:04:15 +0200 Subject: [PATCH] Markdown support --- Discussions/templates/board.html | 8 +++++--- Discussions/templates/board_reply.html | 3 +++ Discussions/templates/boards_new.html | 3 +++ Discussions/templatetags/markdown.py | 28 ++++++++++++++++++++++++++ Discussions/views.py | 1 + LandingPage/static/css/style.css | 5 +++++ LandingPage/templates/base.html | 3 ++- requirements.txt | 2 ++ 8 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 Discussions/templatetags/markdown.py diff --git a/Discussions/templates/board.html b/Discussions/templates/board.html index c05e533..7edb6d4 100644 --- a/Discussions/templates/board.html +++ b/Discussions/templates/board.html @@ -2,6 +2,7 @@ {% block title %} {{board.title}} - {{show.name}} Discussions - Episodes.Community {% endblock %} +{% load markdown %} {% block content %}

Submitted {{board.timestamp}}

-
- {{reply.body}} -
+
{{reply.body|markdown|safe}}
@@ -106,6 +105,9 @@
+
{% endif %} diff --git a/Discussions/templates/board_reply.html b/Discussions/templates/board_reply.html index 2429352..1e49e52 100644 --- a/Discussions/templates/board_reply.html +++ b/Discussions/templates/board_reply.html @@ -21,6 +21,9 @@
+ {% endblock %} diff --git a/Discussions/templates/boards_new.html b/Discussions/templates/boards_new.html index c4a3736..04bfbeb 100644 --- a/Discussions/templates/boards_new.html +++ b/Discussions/templates/boards_new.html @@ -20,6 +20,9 @@
+ {% endblock %} diff --git a/Discussions/templatetags/markdown.py b/Discussions/templatetags/markdown.py new file mode 100644 index 0000000..4946523 --- /dev/null +++ b/Discussions/templatetags/markdown.py @@ -0,0 +1,28 @@ +# Episodes.Community - Community-Driven TV Show Episode Link Sharing Site +# Copyright (C) 2017 Evert "Diamond" Prants , Taizo "Tsa6" Simpson +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +from django import template + +import bleach +import markdown as md +import re + +register = template.Library() + +def markdown(value): + return md.markdown(re.sub(r'\>\;', '>', bleach.clean(value)), output_format="html5") + +register.filter('markdown', markdown) diff --git a/Discussions/views.py b/Discussions/views.py index 0802631..f15f9b8 100644 --- a/Discussions/views.py +++ b/Discussions/views.py @@ -226,6 +226,7 @@ def BoardReplyForm(req, abbr, bid): if err_res: return render(req, "board_reply.html", ctx) + print(form_data['body']) new_reply = form.save(commit=False) new_reply.user = user diff --git a/LandingPage/static/css/style.css b/LandingPage/static/css/style.css index 40b2d15..a928774 100644 --- a/LandingPage/static/css/style.css +++ b/LandingPage/static/css/style.css @@ -210,6 +210,11 @@ footer .logo .part1 { .user-content { word-wrap: break-word; word-break: break-all; + white-space: pre; +} +blockquote { + padding-left: 16px; + border-left: 5px solid #ddd; } @media all and (max-width: 800px) { .logo { diff --git a/LandingPage/templates/base.html b/LandingPage/templates/base.html index 4bd1f6e..e798a6d 100644 --- a/LandingPage/templates/base.html +++ b/LandingPage/templates/base.html @@ -5,7 +5,8 @@ - + + diff --git a/requirements.txt b/requirements.txt index ea18de1..f861e02 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,5 @@ dj-database-url==0.4.2 requests==2.18.4 django-guardian==1.4.9 django-widget-tweaks==1.4.1 +markdown==2.6.11 +bleach==2.1.2