From 59f7431618c9ee5003d6832bdbf7d714ffe65f02 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 26 Nov 2018 13:27:33 +0100 Subject: [PATCH] m.htmlsanity: clarify the use of expand_links a bit. I wanted to remove it at first, but then realized a more proper solution would be to not require the user to add random fields to FORMATTED_FIELDS. In the ideal case the template *could* do just {{ field|render_rst|expand_links(article }} but at the moment Pelican strips all reST formatting from the non-formatted fields, which kinda prevents this. So keeping the filter for later when we have this fixed. --- doc/plugins/htmlsanity.rst | 13 +++++++------ pelican-plugins/m/htmlsanity.py | 4 ++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/doc/plugins/htmlsanity.rst b/doc/plugins/htmlsanity.rst index 98ee485c..8b8cae63 100644 --- a/doc/plugins/htmlsanity.rst +++ b/doc/plugins/htmlsanity.rst @@ -263,14 +263,15 @@ The filter is fully equivalent to the builtin reST rendering and the above `Internal link expansion`_ -------------------------- -By default, link expansion works only in document content and article -summaries. In order to expand links in additional fields and arbitrary strings, -this plugin provides two Jinja2 filters, producing results equivalent to +By default, link expansion works only in document content and fields that are +referenced in the :py:`FORMATTED_FIELDS` (such as article summaries). In order +to expand links in additional fields and arbitrary strings, this plugin +provides two Jinja2 filters, producing results equivalent to `links expanded by Pelican `_. -For fields that are referenced in the :py:`FORMATTED_FIELDS` setting, one can -use the ``expand_links`` Jinja2 filter in the template. The link expansion -needs the content object (either ``article`` or ``page``) as a parameter. +For formatted fields, one can use the ``expand_links`` Jinja2 filter in the +template. The link expansion needs the content object (either ``article`` or +``page``) as a parameter. .. code:: jinja diff --git a/pelican-plugins/m/htmlsanity.py b/pelican-plugins/m/htmlsanity.py index 703ff342..8bb38f15 100644 --- a/pelican-plugins/m/htmlsanity.py +++ b/pelican-plugins/m/htmlsanity.py @@ -648,6 +648,10 @@ def expand_link(link, content): link) def expand_links(text, content): + # TODO: fields that are in FORMATTED_FIELDS are already expanded, but that + # requires extra work on user side. Ideal would be to handle that all on + # template side, so keeping this one for the time when we can replace + # FORMATTED_FIELDS with render_rst as well. return content._update_content(text, content.get_siteurl()) # To be consistent with both what Pelican does now with '/'.join(SITEURL, url) -- 2.30.2