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)
评论列表
文章目录