Replace old version of Tidy with new one
authorMagnus Hagander <magnus@hagander.net>
Fri, 28 Jun 2019 14:22:00 +0000 (16:22 +0200)
committerMagnus Hagander <magnus@hagander.net>
Fri, 28 Jun 2019 14:28:15 +0000 (16:28 +0200)
hamnadmin/hamnadmin/util/html.py

index b5c45b306f9ca7bcd505b4d9459ff7d92dae04ee..8416b5e30d912358e31fe07385a2871e2f8bdf0c 100644 (file)
@@ -1,19 +1,24 @@
 from html.parser import HTMLParser
-import tidy
+import tidylib
 import urllib.parse
 
-_tidyopts = dict(   drop_proprietary_attributes=1,
-                                       alt_text='',
-                                       hide_comments=1,
-                                       output_xhtml=1,
-                                       show_body_only=1,
-                                       clean=1,
-                                       char_encoding='utf8',
-)
-
 def TruncateAndClean(txt):
        # First apply Tidy
-       txt = unicode(str(tidy.parseString(txt.encode('utf-8'), **_tidyopts)),'utf8')
+       (txt, errors) = tidylib.tidy_document(txt,
+                                                                                 options={
+                                                                                         'drop_proprietary_attributes': 1,
+                                                                                         'alt_text': '',
+                                                                                         'hide_comments': 1,
+                                                                                         'output_xhtml': 1,
+                                                                                         'show_body_only': 1,
+                                                                                         'clean': 1,
+                                                                                         'char_encoding': 'utf8',
+                                                                                         'show-warnings': 0,
+                                                                                         'show-info': 0,
+                                                                                 })
+
+       if errors:
+               raise Exception("Tidy failed: %s" % errors)
 
        # Then truncate as necessary
        ht = HtmlTruncator(2048)