1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-19 10:26:17 +00:00

Improve at_find tag and urlize tag

This commit is contained in:
plt
2012-07-31 12:26:10 +08:00
parent 391c25fa40
commit 1779ecfa3d
2 changed files with 13 additions and 3 deletions

View File

@@ -4,11 +4,13 @@ import re
from datetime import datetime
from django import template
from django.utils.safestring import mark_safe
from seahub.settings import FILEEXT_ICON_MAP
from seahub.po import TRANSLATION_MAP
from seahub.profile.models import Profile
register = template.Library()
@register.filter(name='tsstr_sec')
@@ -123,11 +125,11 @@ def url_target_blank(text):
return text.replace('<a ', '<a target="_blank" ')
url_target_blank.is_safe=True
at_pattern = re.compile('(@\w+)', flags=re.U)
at_pattern = re.compile(r'(\s|^)(@\w+)', flags=re.U)
@register.filter(name='find_at')
def find_at(text):
return at_pattern.sub(r'<span class="at-in-msg">\1</span>', text)
return at_pattern.sub(r'\1<span class="at-in-msg">\2</span>', text)
find_at.is_safe=True
@register.filter(name='short_email')
@@ -140,3 +142,11 @@ def short_email(email):
return email
else:
return email[:idx]
@register.filter(name='seahub_urlize')
def seahub_urlize(value, autoescape=None):
"""Converts URLs in plain text into clickable links."""
from seahub.base.utils import urlize
return mark_safe(urlize(value, nofollow=True, autoescape=autoescape))
seahub_urlize.is_safe=True
seahub_urlize.needs_autoescape = True

View File

@@ -102,7 +102,7 @@
<a href="{{ SITE_ROOT }}profile/{{ msg.from_email }}/">{{ msg.from_email|email2nickname }}</a>
</div>
<div class="msg-bd">
<p>{{ msg.message|linebreaksbr|urlize|url_target_blank|find_at }}</p>
<p>{{ msg.message|linebreaksbr|seahub_urlize|find_at }}</p>
{% if msg.reply_cnt == 0 %}
<a class="reply op" href="#" data="{{ msg.id }}">回复</a>
{% else %}