chiark / gitweb /
htmlsanity: Jinja2 filter for hyphenation.
authorVladimír Vondruš <mosra@centrum.cz>
Tue, 4 Jul 2017 09:11:23 +0000 (11:11 +0200)
committerVladimír Vondruš <mosra@centrum.cz>
Wed, 5 Jul 2017 23:02:07 +0000 (01:02 +0200)
pelican-plugins/m/htmlsanity.py

index bbbd61c4e6b45a4d5e0e2869a14deaf34d4a8659..a6f36ce2d2c8d363dce1cce12c6988358552cf82 100644 (file)
@@ -458,8 +458,16 @@ def render_rst(value):
     pub.publish(enable_exit_status=True)
     return pub.writer.parts.get('body')
 
+def hyphenate(value, enable=None, lang=None):
+    if enable is None: enable = enable_hyphenation
+    if lang is None: lang = hyphenation_lang
+    if not enable: return value
+    pyphen_ = pyphen.Pyphen(lang=lang)
+    return words_re.sub(lambda m: pyphen_.inserted(m.group(0), '\u00AD'), str(value))
+
 def configure_pelican(pelicanobj):
     pelicanobj.settings['JINJA_FILTERS']['render_rst'] = render_rst
+    pelicanobj.settings['JINJA_FILTERS']['hyphenate'] = hyphenate
 
     global enable_hyphenation, smart_quotes, hyphenation_lang, docutils_settings
     enable_hyphenation = pelicanobj.settings.get('HTMLSANITY_HYPHENATION', False)