From: Vladimír Vondruš Date: Tue, 4 Jan 2022 15:08:15 +0000 (+0100) Subject: m.htmlsanity: adapt to changes in docutils 0.18+. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=8d77bf2b1bdb3cc9360b33fefdcb2af71ee2892a;p=blog.git m.htmlsanity: adapt to changes in docutils 0.18+. And explicitly test for 0.14, 0,17.1 and 0.18.0 on the CI. --- diff --git a/package/ci/circleci.yml b/package/ci/circleci.yml index 26d29942..9b3f86de 100644 --- a/package/ci/circleci.yml +++ b/package/ci/circleci.yml @@ -48,6 +48,9 @@ commands: attrs-version: type: string default: "" + docutils-version: + type: string + default: "" matplotlib-version: type: string default: "" @@ -59,10 +62,8 @@ commands: name: Install Python dependencies # Pygments 2.11 (and apparently 2.10 as well) treats certain whitespace # differently, I have to update the expected output first. - # Docutils 0.18 drops some attribute that htmlsanity relies on, I need - # to update the code first. command: | - pip install jinja2 docutils==0.17.1 pygments==2.9.0 pelican<< parameters.pelican-version >> Pyphen Pillow coverage codecov qrcode matplotlib<< parameters.matplotlib-version >> attrs<< parameters.attrs-version >> + pip install jinja2 docutils<< parameters.docutils-version >> pygments==2.9.0 pelican<< parameters.pelican-version >> Pyphen Pillow coverage codecov qrcode matplotlib<< parameters.matplotlib-version >> attrs<< parameters.attrs-version >> - run: name: Fix unheard-of cursed issues # otherwise i get Error: unsupported locale setting @@ -188,6 +189,8 @@ jobs: attrs-version: ==19.3.0 matplotlib-version: ==3.3.4 pelican-version: ==4.2.0 + # Ubuntu 18.04 has docutils 0.14 + docutils-version: ==0.14 - checkout - test-theme - test-plugins @@ -207,6 +210,8 @@ jobs: # Matplotlib 3.5 has significantly different output, be sure to have # at least one job testing 3.4 so we don't regress matplotlib-version: ==3.4.3 + # Docutils 0.17 dropped `object_image_types`, test that it works there + docutils-version: ==0.17.1 - checkout - test-theme - test-plugins @@ -220,7 +225,10 @@ jobs: steps: - install-base: extra: graphviz cmake ninja-build wget - - install-python-deps + - install-python-deps: + # Docutils 0.18.0 dropped `in_footnote_list` and made some changes that + # 0.18.1 reverted again, test we're not affected by those + docutils-version: ==0.18.0 - checkout - test-theme - test-plugins diff --git a/plugins/m/htmlsanity.py b/plugins/m/htmlsanity.py index 9fbc6b3e..049cbc72 100644 --- a/plugins/m/htmlsanity.py +++ b/plugins/m/htmlsanity.py @@ -468,16 +468,15 @@ class SaneHtmlTranslator(HTMLTranslator): # Footnote list. Replacing the classes with just .m-footnote. def visit_footnote(self, node): - if not self.in_footnote_list: + previous_node = node.parent[node.parent.index(node)-1] + if not isinstance(previous_node, type(node)): self.body.append('
\n') - self.in_footnote_list = True def depart_footnote(self, node): self.body.append('\n') if not isinstance(node.next_node(descend=False, siblings=True), - nodes.footnote): + type(node)): self.body.append('
\n') - self.in_footnote_list = False # Footnote reference def visit_footnote_reference(self, node): diff --git a/plugins/m/test/__init__.py b/plugins/m/test/__init__.py index b638fbf0..d923a2f7 100644 --- a/plugins/m/test/__init__.py +++ b/plugins/m/test/__init__.py @@ -69,7 +69,14 @@ class PelicanPluginTestCase(unittest.TestCase): 'M_FINE_PRINT': None, 'M_DISABLE_SOCIAL_META_TAGS': True, 'DIRECT_TEMPLATES': [], - 'SLUGIFY_SOURCE': 'basename' + 'SLUGIFY_SOURCE': 'basename', + + 'DOCUTILS_SETTINGS': { + # Default changed to '%' in 0.18, keep the old setting to + # have consistent output across versions + # TODO maybe change this to '%' everywhere instead? + 'auto_id_prefix': 'id' + } } implicit_settings.update(settings) settings = read_settings(path=None, override=implicit_settings)