]> git.p6c8.net - pcdenotes.git/blob - notes/templatetags/notes_extras.py
81674b8c9aa2931db0dc1badcfa60ff4995bbdc6
[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 import calendar
8
9 register = template.Library()
10
11 # See https://python-markdown.github.io/change_log/release-3.0/#safe_mode-and-html_replacement_text-keywords-deprecated
12 class EscapeHtml(Extension):
13 def extendMarkdown(self, md):
14 md.preprocessors.deregister('html_block')
15 md.inlinePatterns.deregister('html')
16
17 @register.filter
18 @stringfilter
19 def markdown(value):
20 return md.markdown(value, extensions=[EscapeHtml(), 'nl2br'])
21
22 @register.filter
23 def month_name(value):
24 return calendar.month_name[value]

patrick-canterino.de