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
- linebreaksli template filter by rokclimb15 5 years, 11 months ago
- filter for extracting a number of paragraphs from any HTML code by rafadev 1 year, 11 months ago
- make an unordered html list by techiegurl 5 years ago
- HTML to text filter by MasonM 4 years, 9 months ago
- Read more link by nny777 4 years, 10 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]
#