lexicon_utils.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:CoBL-public 作者: lingdb 项目源码 文件源码
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))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号