checkwiki.py 文件源码

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

项目:NapalmBot 作者: Facenapalm 项目源码 文件源码
def fix_pair_tag(text, tag, recursive=False):
    """
    Fix self-closing pair tags and return (new_text, replacements_count) tuple.
    tag parameter must contains only name of the tag, for example, "b" for <b>.
    recursive flag must be True if nested tags are correct. The default value is False.
    Checks tag balance: if something going wrong, function willn't change anything.
    Used in 2nd error.
    """
    old_text = text
    correct_tag = "</{}>".format(tag)

    (text, fixed1) = re.subn(r"<[ ]*{}[ ]*[/\\]>".format(tag), correct_tag, text, flags=re.I)
    (text, fixed2) = re.subn(r"<\\[ ]*{}[ ]*>".format(tag), correct_tag, text, flags=re.I)

    if check_tag_balance(text, tag, recursive):
        return (text, fixed1 + fixed2)
    else:
        return (old_text, 0)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号