diff --git a/shared/utils/templates/utils/_text_list.html b/shared/utils/templates/utils/_text_list.html index 7f09137..4c8ac38 100644 --- a/shared/utils/templates/utils/_text_list.html +++ b/shared/utils/templates/utils/_text_list.html @@ -1,5 +1,6 @@ {% load i18n %} {# List of items, where items have a (potentially empty) get_absolute_url and a name attribute #} +{# Usage: {% include "utils/_text_list.html" with items=page.get_authors %} #} {% for item in items %} {% if forloop.last and forloop.counter > 1 %}{% trans "und" %}{% endif %} diff --git a/shared/utils/templatetags/text_tags.py b/shared/utils/templatetags/text_tags.py index 891a324..2e1541d 100644 --- a/shared/utils/templatetags/text_tags.py +++ b/shared/utils/templatetags/text_tags.py @@ -53,3 +53,23 @@ def html_entities_to_unicode(text): @register.filter(needs_autoescape=False) def slimdown(text): return mark_safe(text_utils.slimdown(text)) + + +@register.filter(is_safe=True) +@stringfilter +def html_lines_to_list(value): + """ + Replaces all
tags with ", " + """ + rv = [] + lines = value.split("
") + for i in range(0, len(lines)): + line = lines[i].strip() + rv.append(line) + if i < len(lines) - 1: + if line[-1] not in ";:,.-–—": + rv.append(", ") + else: + rv.append(" ") + return "".join(rv) + return ", ".join([l.strip() for l in value.split("
")])