diff options
author | Aurélien Bompard <aurelien@bompard.org> | 2012-12-05 12:12:11 +0100 |
---|---|---|
committer | Aurélien Bompard <aurelien@bompard.org> | 2012-12-05 12:12:11 +0100 |
commit | 8486805b982b49c1a12f28945ec7346a605d0f5b (patch) | |
tree | 7965cdcbd4ee11a64425e4a73d6653e2592c2875 /hyperkitty/templatetags | |
parent | 716fee916da1096edb865bb43224594574d5a85b (diff) | |
download | hyperkitty-8486805b982b49c1a12f28945ec7346a605d0f5b.tar.gz hyperkitty-8486805b982b49c1a12f28945ec7346a605d0f5b.tar.xz hyperkitty-8486805b982b49c1a12f28945ec7346a605d0f5b.zip |
Snip quoted text in replies
Diffstat (limited to 'hyperkitty/templatetags')
-rw-r--r-- | hyperkitty/templatetags/hk_generic.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/hyperkitty/templatetags/hk_generic.py b/hyperkitty/templatetags/hk_generic.py index bfe234c..18d397f 100644 --- a/hyperkitty/templatetags/hk_generic.py +++ b/hyperkitty/templatetags/hk_generic.py @@ -5,6 +5,8 @@ from dateutil.tz import tzutc, tzoffset from django import template from django.utils.datastructures import SortedDict from django.templatetags.tz import localtime +from django.utils.html import conditional_escape +from django.utils.safestring import mark_safe register = template.Library() @@ -114,3 +116,35 @@ def sender_date(email): def viewer_date(email): email_date = email.date.replace(tzinfo=tzutc()) return localtime(email_date) + + +SNIPPED_RE = re.compile("^\s*>.*$", re.M) +@register.filter(needs_autoescape=True) +def snip_quoted(content, quotemsg="[...]", autoescape=None): + """Snip quoted text in messages""" + if autoescape: + content = conditional_escape(content) + quoted = [] + current_quote = [] + quoting = False + lastline = None + for line in content.split("\n"): + if SNIPPED_RE.match(line): + quoting = True + if lastline == "": + current_quote.append(lastline) + else: + quoting = False + if current_quote: + quoted.append(current_quote[:]) + current_quote = [] + if quoting: + current_quote.append(line) + lastline = line + for quote in quoted: + replaced = ('<a href="#" class="quoted-switch">%s</a>' % quotemsg + +'<span class="quoted-text">\n' + +"\n".join([q for q in quote if q != ""]) + +'</span>') + content = content.replace("\n".join(quote), replaced) + return mark_safe(content) |