from django import template
import re
register = template.Library()
@register.filter(name='html_list')
def make_html_list(value):
"""Break a string down based on newline characters and for each line, enclose it in the
and without the tags.
Similar to the unordered_list filter but not requiring a list"""
value = re.sub(r'\r\n|\r|\n', '\n', value) # normalize newlines
paras = re.split('\n', value)
paras = ['%s' % p.strip().replace('\n', '
') for p in paras]
return '\n\n'.join(paras)