chiark / gitweb /
m.htmlsanity: don't fail so hard if Pyphen is not available.
authorVladimír Vondruš <mosra@centrum.cz>
Wed, 29 Nov 2017 23:23:22 +0000 (00:23 +0100)
committerVladimír Vondruš <mosra@centrum.cz>
Wed, 29 Nov 2017 23:23:22 +0000 (00:23 +0100)
pelican-plugins/m/htmlsanity.py

index 69d7e043316e93c1c3532548380cac186d9ad016..8c155cc70b2089902b257326e43c47258a718ae6 100644 (file)
@@ -180,7 +180,7 @@ class Pyphen(Transform):
                 # I'm assuming this is faster than recreating the instance for
                 # every text node
                 if lang not in pyphen_for_lang:
-                    if lang not in pyphen.LANGUAGES: continue
+                    if not pyphen or lang not in pyphen.LANGUAGES: continue
                     pyphen_for_lang[lang] = pyphen.Pyphen(lang=lang)
 
                 txtnode.parent.replace(txtnode, nodes.Text(words_re.sub(lambda m: pyphen_for_lang[lang].inserted(m.group(0), '\u00AD'), txtnode.astext())))
@@ -600,7 +600,7 @@ def render_rst(value):
 def hyphenate(value, enable=None, lang=None):
     if enable is None: enable = settings['M_HTMLSANITY_HYPHENATION']
     if lang is None: lang = settings['DEFAULT_LANG']
-    if not enable: return value
+    if not enable or not pyphen: return value
     pyphen_ = pyphen.Pyphen(lang=lang)
     return words_re.sub(lambda m: pyphen_.inserted(m.group(0), '&shy;'), str(value))