chiark / gitweb /
m.htmlsanity: patch for difference between docutils 0.13 and 0.14.
authorVladimír Vondruš <mosra@centrum.cz>
Mon, 11 Sep 2017 15:14:00 +0000 (17:14 +0200)
committerVladimír Vondruš <mosra@centrum.cz>
Thu, 14 Sep 2017 22:11:11 +0000 (00:11 +0200)
With the default being for 0.14 (forward-compatible).

pelican-plugins/m/htmlsanity.py

index 172df56434f8a33ee4c8e855132c8db3ded68398..18172d58f78d5286acdcd03de9255e7e4bbad653 100644 (file)
@@ -163,6 +163,14 @@ class SaneHtmlTranslator(HTMLTranslator):
                           ord('@'): '&#64;', # may thwart address harvesters
                           ord('\u00AD'): '&shy;'}
 
+    def __init__(self, document):
+        HTMLTranslator.__init__(self, document)
+
+        # There's a minor difference between docutils 0.13 and 0.14 that breaks
+        # stuff. Monkey-patch it here.
+        if not hasattr(self, 'in_word_wrap_point'):
+            self.in_word_wrap_point = HTMLTranslator.sollbruchstelle
+
     # Somehow this does the trick and removes docinfo from the body. Was
     # present in the HTML4 translator but not in the HTML5 one, so copying it
     # verbatim over
@@ -211,7 +219,7 @@ class SaneHtmlTranslator(HTMLTranslator):
         # Protect text like ``--an-option`` and the regular expression
         # ``[+]?(\d+(\.\d*)?|\.\d+)`` from bad line wrapping
         for token in self.words_and_spaces.findall(text):
-            if token.strip() and self.sollbruchstelle.search(token):
+            if token.strip() and self.in_word_wrap_point.search(token):
                 self.body.append('<span class="pre">%s</span>'
                                     % self.encode(token))
             else: