chiark / gitweb /
m.htmlsanity: fix an exception raised for .. contents:: with a title.
authorVladimír Vondruš <mosra@centrum.cz>
Sun, 9 Jan 2022 11:50:50 +0000 (12:50 +0100)
committerVladimír Vondruš <mosra@centrum.cz>
Sun, 9 Jan 2022 11:52:59 +0000 (12:52 +0100)
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.

plugins/m/htmlsanity.py
plugins/m/test/htmlsanity_content/page.html
plugins/m/test/htmlsanity_content/page.rst

index ce6d6ab18446ccf4685135c545574cf49c17f66a..b1c1e606233dc30ea6c8e9e0e9ddf2cbffddac16 100644 (file)
@@ -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'
 
index 2ef5c60e75245841fcd2f08730eb280bb89dafa2..826f1381517f286c2b2e5e734b0be20eb5aae7e9 100644 (file)
 <li><a href="#section-after" id="id8">Section after</a></li>
 </ul>
 </nav>
+<nav class="m-block m-primary" id="toc-title-to-catch-wrong-assumptions-in-topic-processing">
+<h3>TOC title, to catch wrong assumptions in <code>topic</code> processing</h3>
+<ul>
+<li><a href="#section-title" id="id9">Section title</a><ul>
+<li><a href="#section-title-with-link" id="id10">Section title with link</a></li>
+</ul>
+</li>
+<li><a href="#section-after" id="id11">Section after</a></li>
+</ul>
+</nav>
+<aside class="m-block m-dim">
+<h3>A topic that's not a TOC</h3>
+<p>To catch even more wrong assumptions about <code>topic</code> nodes.</p>
+</aside>
 <p>A paragraph.</p>
 <blockquote>
 A block quote.</blockquote>
@@ -75,7 +89,7 @@ content<br />
 <dd>Description of term 2</dd>
 </dl>
 <section id="section-title">
-<h2><a href="#id6">Section title</a></h2>
+<h2><a href="#id9">Section title</a></h2>
 <p>An <em>emphasised text</em>, <strong>strong text</strong> and a <code>literal</code>. Link to
 <a href="https://google.com">Google</a>, <a href="#a-heading">the heading below</a> or just an
 URL as-is: <a class="m-link-wrap" href="https://mcss.mosra.cz/">https://mcss.mosra.cz/</a>. <a href="mailto:mosra&#64;centrum.cz">E-mail</a>. A footnote
@@ -106,7 +120,7 @@ Clicking on the section header will not include it in the highlight.</p>
 </section>
 <hr />
 <section id="section-after">
-<h2><a href="#id8">Section after</a></h2>
+<h2><a href="#id11">Section after</a></h2>
 <p>Docutils says &quot;Document may not end with a transition&quot;, eh.</p>
 </section>
 <!-- /content -->
index 58c9818a1bd24daf964df0ed01996850634b2ba4..af1347084f239b1aa3c7da0b1a5fb5704a912eaf 100644 (file)
@@ -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.