Browse Source

List to html functions.

master
Erik Stein 7 years ago
parent
commit
ae0c68f620
  1. 1
      shared/utils/templates/utils/_text_list.html
  2. 20
      shared/utils/templatetags/text_tags.py

1
shared/utils/templates/utils/_text_list.html

@ -1,5 +1,6 @@
{% load i18n %} {% load i18n %}
{# List of items, where items have a (potentially empty) get_absolute_url and a name attribute #} {# 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 %} {% for item in items %}
{% if forloop.last and forloop.counter > 1 %}{% trans "und" %}{% endif %} {% if forloop.last and forloop.counter > 1 %}{% trans "und" %}{% endif %}

20
shared/utils/templatetags/text_tags.py

@ -53,3 +53,23 @@ def html_entities_to_unicode(text):
@register.filter(needs_autoescape=False) @register.filter(needs_autoescape=False)
def slimdown(text): def slimdown(text):
return mark_safe(text_utils.slimdown(text)) return mark_safe(text_utils.slimdown(text))
@register.filter(is_safe=True)
@stringfilter
def html_lines_to_list(value):
"""
Replaces all <br> tags with ", "
"""
rv = []
lines = value.split("<br>")
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("<br>")])

Loading…
Cancel
Save