-
-
Save nicholasserra/6bd1ff7650e398127f19 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def escape_text(self, text): | |
"""Use html5lib to escape evil html tags.""" | |
parser = html5lib.HTMLParser(tokenizer=HTMLSanitizer) | |
walker = html5lib.treewalkers.getTreeWalker('etree') | |
stream = walker(parser.parseFragment(text)) | |
serializer = HTMLSerializer(quote_attr_values=True, omit_optional_tags=False, | |
alphabetical_attributes=True) | |
return serializer.render(stream) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment