-{% load markdownify %}
+{% load notes_extras %}
<article{% if note.is_draft %} class="text-muted"{% endif %}>
<h2><a href="{{ note.get_absolute_url }}"{% if note.is_draft %} class="text-muted"{% endif %}>{{ note.title }}</a></h2>
{% if note.is_draft %}<p class="fw-bold">Status: Draft</p>{% endif %}
- <div>{{ note.content|linebreaksbr|markdownify }}</div>
+ <div>{{ note.content|markdown|safe }}</div>
<p class="publication-date">Published on {{ note.created_at|date:"Y-m-d, H:i" }}</p>
</article>
\ No newline at end of file
{% extends "note_base.html" %}
-{% load markdownify %}
{% block title %}{{ note.title }} – Notes{% endblock %}
--- /dev/null
+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
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
- 'markdownify.apps.MarkdownifyConfig',
'notes',
+ 'notes.templatetags.notes_extras'
]
MIDDLEWARE = [
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
-MARKDOWNIFY = {
- "default": {
- #"STRIP": False,
- "BLEACH": False
- }
-}
-
NOTES_PER_PAGE = 5
\ No newline at end of file
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