From a05186c6cbbd2fc434694d126cfdbe70e96be72b Mon Sep 17 00:00:00 2001 From: Weitian LI Date: Tue, 29 Apr 2014 09:06:52 +0800 Subject: * implemented 'my_markdown' templatetag (requires python-markdown) * updated 'list_notice.html' .notice-content with my_markdown tag * added help_text for notice/models.py/Notice contents field --- notice/templatetags/__init__.py | 0 notice/templatetags/my_markdown.py | 26 ++++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 notice/templatetags/__init__.py create mode 100644 notice/templatetags/my_markdown.py (limited to 'notice/templatetags') diff --git a/notice/templatetags/__init__.py b/notice/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/notice/templatetags/my_markdown.py b/notice/templatetags/my_markdown.py new file mode 100644 index 0000000..6b25146 --- /dev/null +++ b/notice/templatetags/my_markdown.py @@ -0,0 +1,26 @@ +# -*- coding: utf8 -*- + +""" +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)) -- cgit v1.2.2