def keeptags(value, tags):
    tags = [re.escape(tag) for tag in tags.split()]

    def _replacer(match):
        if match.group(1) in tags:
            return match.group(0)
        else:
            return ''

    return re.sub(r'</?([^> ]+).*?>', _replacer, value)
dataset/ETHPy150Open danirus/django-wysihtml5/wysihtml5/utils.py/keeptags/original