-
-
Save nicholasserra/e86a2e1762b11643be37 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) | |
return serializer.render(stream) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment