def wikilink(value):
"""
Produce wiki style links to other pages within the database, for use in
comments fields: {{ a_note|wikilink|truncatewords_html:5 }}
Note that it's better to use truncatewords_html with this filter, rather
than plain truncatewords
"""
WIKILINK_RE = re.compile(r"""
(?P<lead>\s|^) # possible leading whitespace
(?P<wikilink>/ # an initial /
(\w+/)+ # multiples of any number of identifier chars + /
)
""",
re.VERBOSE)
def wikilink_sub_callback(match_obj):
link = match_obj.group("wikilink")
lead = match_obj.group("lead")
return '%s<a href="%s">%s</a>' % (lead, escape(link), escape(link))
return mark_safe(WIKILINK_RE.sub(wikilink_sub_callback, value))
评论列表
文章目录