badboy / mdbook-toc

A preprocessor for mdbook to add inline Table of Contents support.
Mozilla Public License 2.0
163 stars 20 forks source link

similarly named headings are not linked correctly #15

Closed simonmichael closed 3 years ago

simonmichael commented 3 years ago

Duplicated headings on a page are not linked correctly, eg: https://hledger.org/hledger.html has a "tags" heading under COMMANDS (https://hledger.org/hledger.html#tags) and a "Tags" heading under JOURNAL FORMAT (https://hledger.org/hledger.html#tags-1). Links in the TOC point only to the first (https://hledger.org/hledger.html#tags). This can be quite confusing.

Related: https://github.com/simonmichael/hledger_site/issues/33, https://github.com/rust-lang/mdBook/issues/1493, https://github.com/rust-lang/mdBook/issues/720

badboy commented 3 years ago

What version of mdbook-toc are you running? We fixed unique slug generation in v0.6. I can't build your site easily, so I can't test it there.

simonmichael commented 3 years ago

@badboy: mdbook-toc 0.6.1.

simonmichael commented 3 years ago

Thanks, I will re-investigate when I get back to this project.

simonmichael commented 3 years ago

I re-tested with mdbook 0.4.7 and mdbook-toc 0.6.2. It seems to work only if case is the same in both headings:

$ mdbook build && grep -i 'tags<' out/a.html
2021-04-20 16:23:37 [INFO] (mdbook::book): Book building has started
2021-04-20 16:23:37 [INFO] (mdbook::book): Running the html backend
<li><a href="#tags">tags</a></li>
<li><a href="#tags-1">tags</a></li>
<h1 id="tags"><a class="header" href="#tags">tags</a></h1>
<h1 id="tags-1"><a class="header" href="#tags-1">tags</a></h1>

My headings have different capitalisation, which causes an incorrect link in the TOC:

$ mdbook build && grep -i 'tags<' out/a.html
2021-04-20 16:23:22 [INFO] (mdbook::book): Book building has started
2021-04-20 16:23:22 [INFO] (mdbook::book): Running the html backend
<li><a href="#tags">tags</a></li>
<li><a href="#tags">Tags</a></li>                                             <- should be "#tags-1"
<h1 id="tags"><a class="header" href="#tags">tags</a></h1>
<h1 id="tags-1"><a class="header" href="#tags-1">Tags</a></h1>
badboy commented 3 years ago

Thanks! That makes a reproducible test case. I might get to look into this in the coming days.

badboy commented 3 years ago

Heh, it was actually just a minor oversight. Fixed now and release on its way.

simonmichael commented 3 years ago

Lovely, thanks for the fix and release.