def strip_tags(s):
    """Resolve HTML entities and remove tags from a string."""

    def handle_match(m):
        name = m.group(1)
        if name in html_entities:
            return chr(html_entities[name])
        if name[:2] in ("#x", "#X"):
            try:
                return chr(int(name[2:], 16))
            except ValueError:
                return ""
        elif name.startswith("#"):
            try:
                return chr(int(name[1:]))
            except ValueError:
                return ""
        return ""

    return _entity_re.sub(handle_match, _striptags_re.sub("", s))
Resolve HTML entities and remove tags from a string.
examples/plnt/utils.py