X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/2c0d3ce5ba9e6e7cd64570028683be4bdb52f52a..ff3358f1faf55a345e8b261b09f942fd63e81f21:/forum/utils/html.py diff --git a/forum/utils/html.py b/forum/utils/html.py index 86a4ef9..6afaf62 100644 --- a/forum/utils/html.py +++ b/forum/utils/html.py @@ -1,6 +1,7 @@ """Utilities for working with HTML.""" -import html5lib -from html5lib import sanitizer, serializer, tokenizer, treebuilders, treewalkers +#import html5lib +from html5lib import sanitizer, serializer, tokenizer, treebuilders, treewalkers, HTMLParser +from django.utils.html import strip_tags from forum.utils.html2text import HTML2Text from django.template import mark_safe from forum import settings @@ -38,7 +39,7 @@ class HTMLSanitizer(tokenizer.HTMLTokenizer, HTMLSanitizerMixin): def sanitize_html(html): """Sanitizes an HTML fragment.""" - p = html5lib.HTMLParser(tokenizer=HTMLSanitizer, + p = HTMLParser(tokenizer=HTMLSanitizer, tree=treebuilders.getTreeBuilder("dom")) dom_tree = p.parseFragment(html) walker = treewalkers.getTreeWalker("dom") @@ -48,6 +49,9 @@ def sanitize_html(html): output_generator = s.serialize(stream) return u''.join(output_generator) +def cleanup_urls(url): + return strip_tags(url) + def html2text(s, ignore_tags=(), indent_width=4, page_width=80): ignore_tags = [t.lower() for t in ignore_tags]