diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/__init__.py | 0 | ||||
-rw-r--r-- | tools/templatetags/__init__.py | 0 | ||||
-rw-r--r-- | tools/templatetags/my_markdown.py | 26 |
3 files changed, 26 insertions, 0 deletions
diff --git a/tools/__init__.py b/tools/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tools/__init__.py diff --git a/tools/templatetags/__init__.py b/tools/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tools/templatetags/__init__.py diff --git a/tools/templatetags/my_markdown.py b/tools/templatetags/my_markdown.py new file mode 100644 index 0000000..842f72f --- /dev/null +++ b/tools/templatetags/my_markdown.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- + +""" +implement my own 'markdown' template tag +requires 'python-markdown' (pip install markdown) +""" +# ref: http://www.dominicrodger.com/django-markdown.html + +import markdown + +from django import template +from django.template.defaultfilters import stringfilter +from django.utils.encoding import force_unicode +from django.utils.safestring import mark_safe + +register = template.Library() + +@register.filter(is_safe=True) +@stringfilter +def my_markdown(value): + extensions = ["nl2br", ] + + return mark_safe(markdown.markdown(force_unicode(value), + extensions, + safe_mode=True, + enable_attributes=False)) |