'Cleans unwanted tags from html for DDG Fathead output
:param html_to_clean: string of html to clean
:return: string of cleaned html'

def _clean_html_tags(self, html_to_clean):

    html_soup_cleaner = BeautifulSoup(html_to_clean, 'html.parser')
    for tag in html_soup_cleaner.find_all('code'):
        if tag.attrs:
            del tag.attrs
    for tag in html_soup_cleaner.find_all('div', {'class': 'highlight-default'}):
        tag.name = 'pre'
        del tag.attrs
        tag.next_element.name = 'code'
        del tag.next_element.attrs
        tag.next_element.next_element.name = 'span'
    tags_to_decompose = ['versionmodified', 'versionadded', 'versionchanged']
    for tag_to_decompose in tags_to_decompose:
        for tag in html_soup_cleaner.find_all('span', {'class': re.compile(tag_to_decompose)}):
            tag.decompose()
        for tag in html_soup_cleaner.find_all('div', {'class': re.compile(tag_to_decompose)}):
            tag.decompose()
    tags_to_replace = ['div', 'blockquote']
    for tag_to_replace in tags_to_replace:
        regex_pattern = '^{}*'.format(tag_to_replace)
        for tag in html_soup_cleaner.find_all(re.compile(regex_pattern)):
            del tag.name
            if tag.attrs:
                del tag.attrs
    regex_pattern = '^{}*'.format('span')
    for tag in html_soup_cleaner.find_all(re.compile(regex_pattern)):
        if tag.attrs:
            if (tag.attrs == {'class': ['prog__sub']}):
                pass
            else:
                del tag.attrs
                del tag.name
        else:
            del tag.name
    for tag in html_soup_cleaner.find_all('a'):
        if tag.attrs:
            del tag.name
            del tag.attrs
    for tag in html_soup_cleaner.find_all('p'):
        if tag.attrs:
            tag.decompose()
    for tag in html_soup_cleaner.find_all('table'):
        if tag.attrs:
            del tag.name
            del tag.attrs
        if tag.ul:
            tag.contents = tag.ul.contents
            tmp_tag = html_soup_cleaner.new_tag('span')
            tmp_tag.attrs = {'class': 'prog__sub'}
            tmp_tag.string = 'Parameters'
            tag.insert(0, tmp_tag)
    for tag in html_soup_cleaner.find_all('em', {'class': 'property'}):
        if tag.attrs:
            del tag.attrs
    for tag in html_soup_cleaner.find_all('cite'):
        tag.name = 'code'
    cleaned_html = str(html_soup_cleaner)
    cleaned_html = cleaned_html.replace('\xc2\xb6', '')
    cleaned_html = cleaned_html.replace('<None>', '')
    cleaned_html = cleaned_html.replace('</None>', '')
    cleaned_html = cleaned_html.replace('<none>', '')
    cleaned_html = cleaned_html.replace('</none>', '')
    cleaned_html = cleaned_html.strip()
    cleaned_html = cleaned_html.replace('\n', '\\n')
    while ('\\n\\n' in cleaned_html):
        cleaned_html = cleaned_html.replace('\\n\\n', '\\n')
    while ('<p></p>' in cleaned_html):
        cleaned_html = cleaned_html.replace('<p></p>', '')
    return cleaned_html
