From e6f24362f46124bd3c4b38fa823b9710cd3f76a7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 4 Jul 2017 11:11:23 +0200 Subject: [PATCH] htmlsanity: Jinja2 filter for hyphenation. --- pelican-plugins/m/htmlsanity.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pelican-plugins/m/htmlsanity.py b/pelican-plugins/m/htmlsanity.py index bbbd61c4..a6f36ce2 100644 --- a/pelican-plugins/m/htmlsanity.py +++ b/pelican-plugins/m/htmlsanity.py @@ -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) -- 2.30.2