diff options
author | Aurélien Bompard <aurelien@bompard.org> | 2012-12-13 15:07:43 +0100 |
---|---|---|
committer | Aurélien Bompard <aurelien@bompard.org> | 2012-12-13 15:07:43 +0100 |
commit | eab3d767b65982e1e04c5538c0d2827f26230fca (patch) | |
tree | 7e881cf8ec8ba8962dda19e135442d621262c55c /hyperkitty/templatetags/hk_generic.py | |
parent | a9d22e8e9cbe51ae353b4e2f68ff635e9cf6d844 (diff) | |
download | hyperkitty-eab3d767b65982e1e04c5538c0d2827f26230fca.tar.gz hyperkitty-eab3d767b65982e1e04c5538c0d2827f26230fca.tar.xz hyperkitty-eab3d767b65982e1e04c5538c0d2827f26230fca.zip |
Improve the quoting style
Refs: #24
Diffstat (limited to 'hyperkitty/templatetags/hk_generic.py')
-rw-r--r-- | hyperkitty/templatetags/hk_generic.py | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/hyperkitty/templatetags/hk_generic.py b/hyperkitty/templatetags/hk_generic.py index fd6897f..b219eba 100644 --- a/hyperkitty/templatetags/hk_generic.py +++ b/hyperkitty/templatetags/hk_generic.py @@ -139,7 +139,7 @@ def viewer_date(email): return localtime(email_date) -SNIPPED_RE = re.compile("^\s*>.*$", re.M) +SNIPPED_RE = re.compile("^(\s*>).*$", re.M) @register.filter(needs_autoescape=True) def snip_quoted(content, quotemsg="[...]", autoescape=None): """Snip quoted text in messages""" @@ -147,25 +147,27 @@ def snip_quoted(content, quotemsg="[...]", autoescape=None): content = conditional_escape(content) quoted = [] current_quote = [] - quoting = False + current_quote_orig = [] lastline = None for line in content.split("\n"): - if SNIPPED_RE.match(line): - quoting = True - if lastline == "": - current_quote.append(lastline) + match = SNIPPED_RE.match(line) + if match is not None: + #if lastline == "": + # current_quote_orig.append(lastline) + current_quote_orig.append(line) + content_start = len(match.group(1)) + current_quote.append(line[content_start:]) else: - quoting = False - if current_quote: - quoted.append(current_quote[:]) + if current_quote_orig: + current_quote_orig.append("") + quoted.append( (current_quote_orig[:], current_quote[:]) ) current_quote = [] - if quoting: - current_quote.append(line) + current_quote_orig = [] 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) + for quote_orig, quote in quoted: + replaced = (' <div class="quoted-switch"><a href="#">%s</a></div>' % quotemsg + +'<div class="quoted-text">' + +"\n".join(quote) + +' </div>') + content = content.replace("\n".join(quote_orig), replaced) return mark_safe(content) |