def error_086_ext_link_two_brackets(text):
"""Fix some cases and return (new_text, replacements_count) tuple."""
# case: [[http://youtube.com/|YouTube]]
def _process_link(match_obj):
"""Deals with founded wiki-link."""
link = match_obj.group(1)
name = match_obj.group(2)
if "wikipedia.org" in link.lower():
link = re.sub(" ", "_", link)
else:
link = re.sub(" ", "%20", link)
return "[" + link + " " + name + "]"
exp1 = r"\[\[(https?://[^|\[\]\n]+)\|([^|\[\]\n]+)\]\]"
(text, count1) = re.subn(exp1, _process_link, text, flags=re.I)
# case: [[http://youtube.com YouTube]]
exp2 = r"\[(\[https?://[^\[\]\n]+\])\]"
(text, count2) = re.subn(exp2, "\\1", text, flags=re.I)
return (text, count1 + count2)
评论列表
文章目录