From a9a319ad49591a45b8bc7803a09a5dca13e3880e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 7 Nov 2017 18:16:21 +0100 Subject: [PATCH] m.htmlsanity: apply hyphenation to everything in FORMATTED_FIELDS. Instead of just the summary. Makes more sense. --- doc/plugins/htmlsanity.rst | 8 ++++---- pelican-plugins/m/htmlsanity.py | 7 ++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/doc/plugins/htmlsanity.rst b/doc/plugins/htmlsanity.rst index 26d269f1..de4b6b6f 100644 --- a/doc/plugins/htmlsanity.rst +++ b/doc/plugins/htmlsanity.rst @@ -163,10 +163,10 @@ screens of mobile devices, where there is just way too much blank space because of long words being wrapped on new lines. The hyphenation is done using `Pyphen `_ and is applied to -whole document contents and article summaries (except for literal and raw -blocks, of course). All other fields including document title are excluded from -hyphenation. You can see it in practice in the following convoluted example, -it's also language-aware: +whole document contents and fields that are included in the :py:`FORMATTED_FIELDS`. +All other fields including document title are excluded from hyphenation, the +same goes for literal and raw blocks. You can see it in practice in the +following convoluted example, it's also language-aware: .. code-figure:: diff --git a/pelican-plugins/m/htmlsanity.py b/pelican-plugins/m/htmlsanity.py index 3a2ca815..69d7e043 100644 --- a/pelican-plugins/m/htmlsanity.py +++ b/pelican-plugins/m/htmlsanity.py @@ -162,10 +162,11 @@ class Pyphen(Transform): isinstance(txtnode.parent, nodes.raw): continue - # From fields include only the summary + # From fields include only the ones that are in + # FORMATTED_FIELDS if isinstance(txtnode.parent.parent, nodes.field_body): field_name_index = txtnode.parent.parent.parent.first_child_matching_class(nodes.field_name) - if txtnode.parent.parent.parent[field_name_index][0] != 'summary': + if txtnode.parent.parent.parent[field_name_index][0] not in settings['FORMATTED_FIELDS']: continue # Useful for debugging, don't remove ;) @@ -721,7 +722,7 @@ def configure_pelican(pelicanobj): global settings settings['M_HTMLSANITY_HYPHENATION'] = pelicanobj.settings.get('M_HTMLSANITY_HYPHENATION', False) settings['M_HTMLSANITY_SMART_QUOTES'] = pelicanobj.settings.get('M_HTMLSANITY_SMART_QUOTES', False) - for i in 'DEFAULT_LANG', 'DOCUTILS_SETTINGS', 'INTRASITE_LINK_REGEX', 'SITEURL': + for i in 'DEFAULT_LANG', 'DOCUTILS_SETTINGS', 'INTRASITE_LINK_REGEX', 'SITEURL', 'FORMATTED_FIELDS': settings[i] = pelicanobj.settings[i] def add_reader(readers): -- 2.30.2