import re
import html


def strip_html(func):
    """A decorator which, when applied to a function, will add a 'strip_html'
    keyword argument - if set to True this will strip any HTML from the
    function's output."""

    cleaner = re.compile("<.*?>")
    def new_func(*args, strip_html=False, **kwargs):
        name = func(*args, **kwargs)
        if strip_html:
            if isinstance(name, str):
                return html.unescape(re.sub(cleaner, "", name))
            elif isinstance(name, list) or isinstance(name, tuple):
                return type(name)([html.unescape(re.sub(cleaner, "", n)) for n in name])
        else:
            return name
    new_func.__name__ = func.__name__
    new_func.__doc__ = func.__doc__
    return new_func