import re


def clean_line(line):
    """
    Cleans a string from HTML tags and Wiki markup
    
    Returns
    --------
    str
        Returns a string that is cleaned
    """

    refs = re.findall('\<ref.*?\<\/ref\>', line)
    for ref in refs:
        line = line.replace(ref, " ")
    # remove all <ref/>'s
    refs = re.findall('\<ref.*?\/\>', line)
    for ref in refs:
        line = line.replace(ref, " ")
    # remove all <math
    tags = re.findall('\<math.*?\<\/math\>', line)
    for tag_match in tags:
        line = line.replace(tag_match, "")
    # remove all inline {{ }}'s
    brackets = re.findall('\{\{.*?\}\}', line)
    for bracket_match in brackets:
        line = line.replace(bracket_match, "")
    # remove all inline {| |}'s
    brackets = re.findall('\{\|.*?\|\}', line)
    for bracket_match in brackets:
        line = line.replace(bracket_match, "")
    # replace brackets
    line = line.replace("'''", "")
    # remove crefs with locations
    crefs = re.findall('\[\[.*?\]\]', line)
    for cref in crefs:
        cref_parsed = cref[2:-2].split("|")
        line = line.replace(cref, cref_parsed[-1])
    # remove cref brackets (left overs)
    line = line.replace("[[", "").replace("]]", "")
    # remove HTML notes (inline)
    refs = re.findall('\<\!--.*?\--\>', line)
    for ref in refs:
        line = line.replace(ref, " ")
    # remove thumb| |
    brackets = re.findall('thumb\|.*?\|', line)
    for bracket_match in brackets:
        line = line.replace(bracket_match, "")
    # remove thumb|
    line = line.replace("thumb|", "")
    return line