From: Vladimír Vondruš Date: Sun, 9 Jan 2022 11:50:50 +0000 (+0100) Subject: m.htmlsanity: fix an exception raised for .. contents:: with a title. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=c661a654d3d3837dfae92e48bfccde19ceea6dad;p=blog.git m.htmlsanity: fix an exception raised for .. contents:: with a title. I have a hunch I was looking at this corner case, but of course forgot to actually try it out. Extending the test to prevent this from regressing again in the future. --- diff --git a/plugins/m/htmlsanity.py b/plugins/m/htmlsanity.py index ce6d6ab1..b1c1e606 100644 --- a/plugins/m/htmlsanity.py +++ b/plugins/m/htmlsanity.py @@ -390,7 +390,9 @@ class SaneHtmlTranslator(HTMLTranslator): if 'contents' in node['classes']: node.html_tagname = 'nav' node['classes'].remove('contents') - node['ids'].remove('contents') + # If the TOC has a title, the ID will be different, and in that + # case we'll leave it there. + if 'contents' in node['ids']: node['ids'].remove('contents') else: node.html_tagname = 'aside' diff --git a/plugins/m/test/htmlsanity_content/page.html b/plugins/m/test/htmlsanity_content/page.html index 2ef5c60e..826f1381 100644 --- a/plugins/m/test/htmlsanity_content/page.html +++ b/plugins/m/test/htmlsanity_content/page.html @@ -33,6 +33,20 @@
  • Section after
  • + +

    A paragraph.

    A block quote.
    @@ -75,7 +89,7 @@ content
    Description of term 2
    -

    Section title

    +

    Section title

    An emphasised text, strong text and a literal. Link to Google, the heading below or just an URL as-is: https://mcss.mosra.cz/. E-mail. A footnote @@ -106,7 +120,7 @@ Clicking on the section header will not include it in the highlight.


    -

    Section after

    +

    Section after

    Docutils says "Document may not end with a transition", eh.

    diff --git a/plugins/m/test/htmlsanity_content/page.rst b/plugins/m/test/htmlsanity_content/page.rst index 58c9818a..af134708 100644 --- a/plugins/m/test/htmlsanity_content/page.rst +++ b/plugins/m/test/htmlsanity_content/page.rst @@ -6,6 +6,14 @@ A page .. contents:: :class: m-block m-default +.. contents:: TOC title, to catch wrong assumptions in ``topic`` processing + :class: m-block m-primary + +.. topic:: A topic that's not a TOC + :class: m-block m-dim + + To catch even more wrong assumptions about ``topic`` nodes. + A paragraph. A block quote.