Skip to content

Duplicate headings inside and outside the TOC tree break TOC links #63

Closed
@davidtheclark

Description

@davidtheclark

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions