-
-
Notifications
You must be signed in to change notification settings - Fork 279
Reference links not rendered in table of contents links #426
Copy link
Copy link
Closed
Description
Reference links are not rendered in table of contents links (they are left as [link][ref]). Inline links and other formatting do seem to work (specifically, the HTML is stripped).
I think the root cause is similar to #378 (comment), state not being passed around when the TOC ul is rendered; the fix probably involves passing the parent state to normalize_toc_item here.
This did use to work in v2; together with the fact that links are allowed in headings, I'd tend to consider it a regression.
Repro (mistune 3.1.4):
>>> from mistune import *
>>> from mistune.directives import *
>>> md = create_markdown(plugins=[RSTDirective([TableOfContents()])])
>>> s = """
... .. toc::
... # **bold**
... # [inline link](example.com)
... # [link ref][ref]
... [ref]: example.com
... """
>>> print(md(s))
<details class="toc" open>
<summary>Table of Contents</summary>
<ul>
<li><a href="#toc_1">bold</a></li>
<li><a href="#toc_2">inline link</a></li>
<li><a href="#toc_3">[link ref][ref]</a></li>
</ul>
</details>
<h1 id="toc_1"><strong>bold</strong></h1>
<h1 id="toc_2"><a href="example.com">inline link</a></h1>
<h1 id="toc_3"><a href="example.com">link ref</a></h1>Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels