iss_bbcode.py 文件源码

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

项目:ISS 作者: RyanJenkins 项目源码 文件源码
def _add_shortcode_preprocessor(parser):
    global shortcode_pat
    global shortcode_map

    if not shortcode_map:
        shortcode_map = utils.get_config('shortcode_map')

    if not shortcode_pat:
        scp = []
        for name, _ in shortcode_map.items():
            scp.append(name)

        shortcode_pat = re.compile(':(%s):' % '|'.join(scp), flags=re.IGNORECASE)


    def _preprocess_shortcode(text):
        def _repl(match):
            name = match.group(1)
            if name in shortcode_map:
                return '[shortcode]%s[/shortcode]' % name
            else:
                return match.group(0)

        return re.sub(shortcode_pat, _repl, text)

    parser.add_preprocessor(_preprocess_shortcode)
    return parser
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号