Markdown preview emits duplicate heading ids when a heading matches a generated suffix
- Dominant language
- TypeScript
- Stars
- 193k
- Forks
- 42.4k
- PR merge metrics
- PR metrics pending
Description
### Bug description
The markdown preview slug builder (`extensions/markdown-language-features/src/slugify.ts`, `createBuilder`) deduplicates heading ids but never registers the `-N` suffixed id it generates, only the base slug. So a document containing the headings `Foo`, `Foo-1`, `Foo` produces DOM anchors:
- expected (github-slugger semantics): `foo`, `foo-1`, `foo-2`
- observed: `foo`, `foo-1`, `foo-1`
The third heading's dedupe builds `foo-1` from the base counter and hands it out again even though that id was already used by the second heading. Duplicate ids break scrolling to anchors pasted from github.com URLs into the preview.
### Steps to reproduce
1. Preview a markdown file with headings `Foo`, `Foo-1`, `Foo`.
2. Inspect the header element ids: two elements share `foo-1`.
### Expected behavior
Every emitted id including generated suffixes is recorded; later duplicates advance until a free id, byte-for-byte matching github-slugger behavior.
### Version tested
Commit `38ec3d57f91b` on `main`; reproduced against compiled module output and verified against github-slugger@2.0.0 as reference. A fix is ready with a dedicated unit test file.
Contributor guide
Research direction
Start at createBuilder in extensions/markdown-language-features/src/slugify.ts and reproduce the Foo, Foo-1, Foo heading sequence in the markdown preview. Compare the emitted ids with foo, foo-1, foo-2 and the github-slugger@2.0.0 behavior; done means generated suffixes remain unique and the dedicated unit test passes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 70/100