From 74d76ca0dac6af53226c85028e7454b7635a4ffb Mon Sep 17 00:00:00 2001 From: Justin Mayer Date: Tue, 14 Jan 2025 11:39:17 +0100 Subject: [PATCH 1/6] Pin Pygments due to indentation changes in 2.19 --- pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 813b098cc..f4ce80cd7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,7 +34,7 @@ dependencies = [ "feedgenerator>=2.1.0", "jinja2>=3.1.2", "ordered-set>=4.1.0", - "pygments>=2.16.1", + "pygments>=2.16.1,<2.19.0", "python-dateutil>=2.8.2", "rich>=13.6.0", "unidecode>=1.3.7", @@ -88,7 +88,7 @@ dev = [ "furo==2023.9.10", "livereload>=2.6.3", "psutil>=5.9.6", - "pygments>=2.16.1", + "pygments>=2.16.1,<2.19.0", "pytest>=7.4.3", "pytest-cov>=4.1.0", "pytest-sugar>=0.9.7", From 7a4c89f64af9940cc9d07d979e7c23877c1677b3 Mon Sep 17 00:00:00 2001 From: David Lesieur Date: Thu, 26 Dec 2024 19:05:16 -0500 Subject: [PATCH 2/6] Adjust test following changes in Typogrify. Typogrify's 'widont' filter used to ignore the list of 'ignore_tags', but this got fixed in Typogrify. --- pelican/tests/test_readers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pelican/tests/test_readers.py b/pelican/tests/test_readers.py index 68938a83a..e13cbb118 100644 --- a/pelican/tests/test_readers.py +++ b/pelican/tests/test_readers.py @@ -417,7 +417,7 @@ def test_typogrify_ignore_tags(self): path="article.rst", TYPOGRIFY=True, TYPOGRIFY_IGNORE_TAGS=["p"] ) expected = ( - "

THIS is some content. With some stuff to " + "

THIS is some content. With some stuff to " ""typogrify"...

\n

Now with added " 'support for ' "TLA.

\n" From b4fcb7f4e34c415dce457a91426c5966bb8ffd84 Mon Sep 17 00:00:00 2001 From: David Lesieur Date: Fri, 27 Dec 2024 16:42:15 -0500 Subject: [PATCH 3/6] Remove obsolete comment regarding widont. --- pelican/tests/test_readers.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pelican/tests/test_readers.py b/pelican/tests/test_readers.py index e13cbb118..4372fea16 100644 --- a/pelican/tests/test_readers.py +++ b/pelican/tests/test_readers.py @@ -411,8 +411,7 @@ def test_typogrify_summary(self): def test_typogrify_ignore_tags(self): try: - # typogrify should be able to ignore user specified tags, - # but tries to be clever with widont extension + # typogrify should be able to ignore user specified tags. page = self.read_file( path="article.rst", TYPOGRIFY=True, TYPOGRIFY_IGNORE_TAGS=["p"] ) From b3ef32bcf143479283e853b5b7561a2c840cfe66 Mon Sep 17 00:00:00 2001 From: Justin Mayer Date: Tue, 14 Jan 2025 12:35:17 +0100 Subject: [PATCH 4/6] test: Require Typogrify 2.1+ to pass updated test --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index f4ce80cd7..02a1d56a1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -82,7 +82,7 @@ dev = [ "jinja2>=3.1.2", "lxml>=4.9.3", "markdown>=3.5.1", - "typogrify>=2.0.7", + "typogrify>=2.1.0", "sphinx>=7.1.2", "sphinxext-opengraph>=0.9.0", "furo==2023.9.10", From 9207e1ff62e109badb2f94fde1326ad0b2a1927a Mon Sep 17 00:00:00 2001 From: David Lesieur Date: Tue, 14 Jan 2025 06:48:39 -0500 Subject: [PATCH 5/6] feat: Add setting to omit selected Typogrify filters. Fixes #3436 (#3439) --- docs/settings.rst | 9 +++- pelican/readers.py | 17 +++++-- pelican/settings.py | 1 + pelican/tests/test_readers.py | 84 +++++++++++++++++++++++++++++++++++ 4 files changed, 107 insertions(+), 4 deletions(-) diff --git a/docs/settings.rst b/docs/settings.rst index b442451a2..72c72fb1e 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -288,7 +288,14 @@ Basic settings A list of tags for Typogrify to ignore. By default Typogrify will ignore ``pre`` and ``code`` tags. This requires that Typogrify version 2.0.4 or - later is installed + later is installed. + +.. data:: TYPOGRIFY_OMIT_FILTERS = [] + + A list of Typogrify filters to skip. Allowed values are: ``'amp'``, + ``'smartypants'``, ``'caps'``, ``'initial_quotes'``, ``'widont'``. By + default, no filter is omitted (in other words, all filters get applied). This + setting requires that Typogrify version 2.1.0 or later is installed. .. data:: TYPOGRIFY_DASHES = 'default' diff --git a/pelican/readers.py b/pelican/readers.py index 59aa7ca33..182194fe1 100644 --- a/pelican/readers.py +++ b/pelican/readers.py @@ -648,11 +648,22 @@ def read_file( smartypants.Attr.default |= smartypants.Attr.w def typogrify_wrapper(text): - """Ensures ignore_tags feature is backward compatible""" + """Ensure compatibility with older versions of Typogrify. + + The 'TYPOGRIFY_IGNORE_TAGS' and/or 'TYPOGRIFY_OMIT_FILTERS' + settings will be ignored if the installed version of Typogrify + doesn't have the corresponding features.""" try: - return typogrify(text, self.settings["TYPOGRIFY_IGNORE_TAGS"]) + return typogrify( + text, + self.settings["TYPOGRIFY_IGNORE_TAGS"], + **{f: False for f in self.settings["TYPOGRIFY_OMIT_FILTERS"]}, + ) except TypeError: - return typogrify(text) + try: + typogrify(text, self.settings["TYPOGRIFY_IGNORE_TAGS"]) + except TypeError: + return typogrify(text) if content: content = typogrify_wrapper(content) diff --git a/pelican/settings.py b/pelican/settings.py index 69120058a..1fb0b2111 100644 --- a/pelican/settings.py +++ b/pelican/settings.py @@ -149,6 +149,7 @@ def load_source(name: str, path: str) -> ModuleType: "ARTICLE_PERMALINK_STRUCTURE": "", "TYPOGRIFY": False, "TYPOGRIFY_IGNORE_TAGS": [], + "TYPOGRIFY_OMIT_FILTERS": [], "TYPOGRIFY_DASHES": "default", "SUMMARY_END_SUFFIX": "…", "SUMMARY_MAX_LENGTH": 50, diff --git a/pelican/tests/test_readers.py b/pelican/tests/test_readers.py index 4372fea16..751088f7a 100644 --- a/pelican/tests/test_readers.py +++ b/pelican/tests/test_readers.py @@ -409,6 +409,90 @@ def test_typogrify_summary(self): except ImportError: return unittest.skip("need the typogrify distribution") + def test_typogrify_ignore_filters(self): + try: + # typogrify should be able to ignore user specified filters. + page = self.read_file( + path="article_with_code_block.rst", + TYPOGRIFY=True, + TYPOGRIFY_OMIT_FILTERS=["amp"], + ) + expected = ( + "

An article with some code

\n" + '
'
+                'x'
+                ' &'
+                ' y\n
\n' + "

A block quote:

\n
\nx " + "& y
\n" + "

Normal:\nx & y

\n" + ) + self.assertEqual(page.content, expected) + + page = self.read_file( + path="article.rst", + TYPOGRIFY=True, + TYPOGRIFY_OMIT_FILTERS=["smartypants"], + ) + expected = ( + '

THIS is some content. ' + "With some stuff to "typogrify"...

\n" + '

Now with added support for TLA.

\n' + ) + self.assertEqual(page.content, expected) + + page = self.read_file( + path="article.rst", + TYPOGRIFY=True, + TYPOGRIFY_OMIT_FILTERS=["caps"], + ) + expected = ( + "

THIS is some content. " + "With some stuff to “typogrify”…

\n" + '

Now with added support for TLA.

\n' + ) + self.assertEqual(page.content, expected) + + page = self.read_file( + path="article.rst", + TYPOGRIFY=True, + TYPOGRIFY_OMIT_FILTERS=["initial_quotes"], + ) + expected = ( + '

THIS is some content. ' + "With some stuff to “typogrify”…

\n" + '

Now with added support for TLA.

\n' + ) + self.assertEqual(page.content, expected) + + page = self.read_file( + path="article.rst", + TYPOGRIFY=True, + TYPOGRIFY_OMIT_FILTERS=["widont"], + ) + expected = ( + '

THIS is some content. ' + "With some stuff to " + "“typogrify”…

\n

Now with added " + 'support for ' + 'TLA.

\n' + ) + self.assertEqual(page.content, expected) + + page = self.read_file( + path="article.rst", + TYPOGRIFY=True, + TYPOGRIFY_OMIT_FILTERS=["this-filter-does-not-exists"], + ) + self.assertRaises(TypeError) + except ImportError: + return unittest.skip("need the typogrify distribution") + except TypeError: + return unittest.skip("need typogrify version 2.1.0 or later") + def test_typogrify_ignore_tags(self): try: # typogrify should be able to ignore user specified tags. From 8a1c55ed07f9d749e7f45c1711f63fb93a51daa7 Mon Sep 17 00:00:00 2001 From: Justin Mayer Date: Tue, 14 Jan 2025 12:49:34 +0100 Subject: [PATCH 6/6] docs: Clarify namespace plugin loading order --- docs/plugins.rst | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/docs/plugins.rst b/docs/plugins.rst index 22e1bcc6d..58eee16b9 100644 --- a/docs/plugins.rst +++ b/docs/plugins.rst @@ -94,12 +94,14 @@ which you map the signals to your plugin logic. Let's take a simple example:: your ``register`` callable or they will be garbage-collected before the signal is emitted. -If multiple plugins connect to the same signal, plugins will be executed in the -order they are connected. With ``PLUGINS`` setting, order will be as defined in -the setting. If you rely on auto-discovered namespace plugins, no ``PLUGINS`` -setting, they will be connected in the same order they are discovered (same -order as ``pelican-plugins`` output). If you want to specify the order -explicitly, disable auto-discovery by defining ``PLUGINS`` in the desired order. +If multiple plugins connect to the same signal, plugins will be invoked in the +order they are registered. When the ``PLUGINS`` setting is defined, plugin +invocation order will be the order in which the plugins are listed in the +``PLUGINS`` setting. If you rely on auto-discovered namespace plugins and have +no ``PLUGINS`` setting defined, plugins will be invoked in the same order that +they are discovered (the same order as listed in the output of the +``pelican-plugins`` command). If you want to specify the order explicitly, +disable auto-discovery by defining ``PLUGINS`` in the desired order. Namespace plugin structure --------------------------