Commit a5098513 authored by Michal Čihař's avatar Michal Čihař

Highlight whitespaces and keep newlines in strings

parent 22f7d39d
...@@ -53,3 +53,8 @@ ul.breadcums li { ...@@ -53,3 +53,8 @@ ul.breadcums li {
.translatetext { .translatetext {
background-color: #eee; background-color: #eee;
} }
.hlspace {
border-bottom: 1px dotted red;
white-space: pre;
display: inline-block;
}
from django.template.defaultfilters import stringfilter from django.template.defaultfilters import stringfilter
from django.utils.html import escape from django.utils.html import escape
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from django.utils.encoding import force_unicode
from django import template from django import template
import re
register = template.Library() register = template.Library()
def fmt_whitespace(value):
value = re.sub(r'( +| $|^ )', '<span class="hlspace">\\1</span>', value)
return value
@register.filter @register.filter
@stringfilter @stringfilter
def fmttranslation(s): def fmttranslation(value):
s = escape(s) value = escape(force_unicode(value))
return mark_safe(s) value = re.sub(r'\r\n|\r|\n', '\n', value) # normalize newlines
paras = re.split('\n', value)
paras = [fmt_whitespace(p) for p in paras]
value = '<br />'.join(paras)
return mark_safe(value)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment