checkwiki.py 文件源码

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

项目:NapalmBot 作者: Facenapalm 项目源码 文件源码
def fix_unpair_tag(text, tag, count_selfclosing=True):
    """
    Fix self-closing unpair tags and return (new_text, replacements_count) tuple.
    tag parameter must contains only name of the tag, for example, "br" for <br>.
    If self-closing tags are correct, set count_selfclosing param to False.
    self-closing still will be corrected in the name of unification, but those
    replacements will not be counted.
    Used in 2nd error.
    """
    correct_tag = "<{}>".format(tag)
    all_tags = r"<[/\\ ]*{}[/\\ ]*>".format(tag)

    if count_selfclosing:
        correct = count_ignore_case(text, correct_tag)
    else:
        correct = len(re.findall(r"<{}\s*/?>".format(tag), text))
    (text, fixed) = re.subn(all_tags, correct_tag, text, flags=re.I)
    return (text, fixed - correct)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号