]> git.p6c8.net - pcdenotes.git/blob - notes/templatetags/notes_extras.py
3cdb2333798ab459b92b2836448da1cce99c67a2
[pcdenotes.git] / notes / templatetags / notes_extras.py
1 from django import template
2 from django.template.defaultfilters import stringfilter
3
4 import markdown as md
5 from markdown.extensions import Extension
6
7 register = template.Library()
8
9 # See https://python-markdown.github.io/change_log/release-3.0/#safe_mode-and-html_replacement_text-keywords-deprecated
10 class EscapeHtml(Extension):
11 def extendMarkdown(self, md):
12 md.preprocessors.deregister('html_block')
13 md.inlinePatterns.deregister('html')
14
15 @register.filter
16 @stringfilter
17 def markdown(value):
18 return md.markdown(value, extensions=[EscapeHtml(), 'nl2br'])

patrick-canterino.de