diff --git a/isso/tests/test_html.py b/isso/tests/test_html.py index 2b3b15c..6eb037b 100644 --- a/isso/tests/test_html.py +++ b/isso/tests/test_html.py @@ -59,7 +59,6 @@ class TestHTML(unittest.TestCase): print("Hello, World") """) - @unittest.skipIf(html.HTML5LIB_VERSION <= html.HTML5LIB_SIMPLETREE, "backport") def test_sanitizer(self): sanitizer = html.Sanitizer(elements=[], attributes=[]) examples = [ @@ -73,11 +72,10 @@ class TestHTML(unittest.TestCase): for (input, expected) in examples: if isinstance(expected, list): - self.assertIn(html.sanitize(sanitizer, input), expected) + self.assertIn(sanitizer.sanitize(input), expected) else: - self.assertEqual(html.sanitize(sanitizer, input), expected) + self.assertEqual(sanitizer.sanitize(input), expected) - @unittest.skipIf(html.HTML5LIB_VERSION <= html.HTML5LIB_SIMPLETREE, "backport") def test_sanitizer_extensions(self): sanitizer = html.Sanitizer(elements=["img"], attributes=["src"]) examples = [ @@ -85,7 +83,7 @@ class TestHTML(unittest.TestCase): ('', '')] for (input, expected) in examples: - self.assertEqual(html.sanitize(sanitizer, input), expected) + self.assertEqual(sanitizer.sanitize(input), expected) def test_render(self): conf = config.new({ diff --git a/isso/utils/html.py b/isso/utils/html.py index 4acfcc0..306dbd2 100644 --- a/isso/utils/html.py +++ b/isso/utils/html.py @@ -6,61 +6,30 @@ import pkg_resources from distutils.version import LooseVersion as Version -HTML5LIB_VERSION = Version(pkg_resources.get_distribution("html5lib").version) -HTML5LIB_SIMPLETREE = Version("0.95") - -import html5lib -from html5lib.sanitizer import HTMLSanitizer -from html5lib.serializer import HTMLSerializer - +import bleach import misaka -def Sanitizer(elements, attributes): - - class Inner(HTMLSanitizer): +class Sanitizer(object): + def __init__(self, elements, attributes): # attributes found in Sundown's HTML serializer [1] # except for tag, # because images are not generated anyways. # # [1] https://github.com/vmg/sundown/blob/master/html/html.c - allowed_elements = ["a", "p", "hr", "br", "ol", "ul", "li", + self.elements = ["a", "p", "hr", "br", "ol", "ul", "li", "pre", "code", "blockquote", "del", "ins", "strong", "em", "h1", "h2", "h3", "h4", "h5", "h6", "table", "thead", "tbody", "th", "td"] + elements # href for and align for