1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | from django.template import Library, Node
from django.template.defaultfilters import stringfilter
import re
register = Library()
def paragraphs(value):
"""
Turns paragraphs delineated with newline characters into
paragraphs wrapped in <p> and </p> HTML tags.
"""
paras = re.split(r'[\r\n]+', value)
paras = ['<p>%s</p>' % p.strip() for p in paras]
return '\n'.join(paras)
paragraphs = stringfilter(paragraphs)
register.filter(paragraphs)
|
More like this
- Template filter to get a list element by its index by abidibo 3 weeks, 1 day ago
- PyIfTag - Just like python if expression by limodou 5 years, 3 months ago
- Twitter template tags and filters by moxypark 1 year, 9 months ago
- Yet another SQL debugging facility by miracle2k 4 years, 9 months ago
- NewForms Readonly / Edit Pattern by FreddieP 4 years, 5 months ago
Comments
I would simplify
to
#
@Archatas,
Good suggestion. Thanks!
#
buit-in tag in Django: linebreaks
https://docs.djangoproject.com/en/dev/ref/templates/builtins/#linebreaks
#
Oh, sorry this tag add [HTML_REMOVED] into [HTML_REMOVED][HTML_REMOVED]
#