syntax-tree/mdast-util-toc

Duplicate headings inside and outside the TOC tree break TOC links

davidtheclark opened this issue · 0 comments

Subject of the issue

If you provide a heading value, so the TOC tree is a subtree of the entire document; and a heading inside the TOC tree is a duplicate of one before the TOC tree; then the slug link for that TOC heading will be inaccurate.

This surfaced in cosmiconfig/cosmiconfig#225, where the document's H1, outside the TOC, is cosmiconfig, and a subheading within the TOC is cosmiconfig() (same slug).

I think I see the problem in the code and will submit a PR.

Your environment

I've tested this with the latest version.

Steps to reproduce

With this markdown ...

# Title

## Table of contents

## Title

... the TOC's link to the ## Title heading should be #title-1; but it's currently #title.