From: Patrick Canterino Date: Sun, 13 Feb 2022 10:23:20 +0000 (+0100) Subject: Changed way of generating HTML X-Git-Url: https://git.p6c8.net/pcdenotes.git/commitdiff_plain/69d7df229ddc5c993178928ad91f3273080da42c?hp=c72b86bdd8c5a7b826a5b02cfbc1928c8bd8d509 Changed way of generating HTML - Use python-markdown directly without django-markdownify - Don't use linebreaksbr template filter - Linebreaks are now created using

and so on - blockquotes work now (they didn't work because of linebreaksbr) --- diff --git a/notes/templates/note.html b/notes/templates/note.html index ddc9c11..b2b7519 100644 --- a/notes/templates/note.html +++ b/notes/templates/note.html @@ -1,7 +1,7 @@ -{% load markdownify %} +{% load notes_extras %}

{{ note.title }}

{% if note.is_draft %}

Status: Draft

{% endif %} -
{{ note.content|linebreaksbr|markdownify }}
+
{{ note.content|markdown|safe }}

Published on {{ note.created_at|date:"Y-m-d, H:i" }}

\ No newline at end of file diff --git a/notes/templates/note_detail.html b/notes/templates/note_detail.html index 0feb681..d15296d 100644 --- a/notes/templates/note_detail.html +++ b/notes/templates/note_detail.html @@ -1,5 +1,4 @@ {% extends "note_base.html" %} -{% load markdownify %} {% block title %}{{ note.title }} – Notes{% endblock %} diff --git a/notes/templatetags/__init__.py b/notes/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/notes/templatetags/notes_extras.py b/notes/templatetags/notes_extras.py new file mode 100644 index 0000000..3cdb233 --- /dev/null +++ b/notes/templatetags/notes_extras.py @@ -0,0 +1,18 @@ +from django import template +from django.template.defaultfilters import stringfilter + +import markdown as md +from markdown.extensions import Extension + +register = template.Library() + +# See https://python-markdown.github.io/change_log/release-3.0/#safe_mode-and-html_replacement_text-keywords-deprecated +class EscapeHtml(Extension): + def extendMarkdown(self, md): + md.preprocessors.deregister('html_block') + md.inlinePatterns.deregister('html') + +@register.filter +@stringfilter +def markdown(value): + return md.markdown(value, extensions=[EscapeHtml(), 'nl2br']) \ No newline at end of file diff --git a/pcdenotes/settings.py b/pcdenotes/settings.py index 88b705d..1c79c5c 100644 --- a/pcdenotes/settings.py +++ b/pcdenotes/settings.py @@ -43,8 +43,8 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', - 'markdownify.apps.MarkdownifyConfig', 'notes', + 'notes.templatetags.notes_extras' ] MIDDLEWARE = [ @@ -139,11 +139,4 @@ STATICFILES_DIRS = [BASE_DIR / 'notes/static'] DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' -MARKDOWNIFY = { - "default": { - #"STRIP": False, - "BLEACH": False - } -} - NOTES_PER_PAGE = 5 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 5d73732..f37921d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,5 @@ asgiref==3.4.1 -bleach==4.1.0 Django==3.2.12 -django-markdownify==0.9.0 importlib-metadata==4.8.3 Markdown==3.3.6 mysqlclient==2.1.0