fix: recognize HTML heading in no-missing-link-fragments#583
Merged
fix: recognize HTML heading in no-missing-link-fragments#583
no-missing-link-fragments#583Conversation
1 task
This comment was marked as resolved.
This comment was marked as resolved.
…cognize-html-heading-in-no-missing-link-fragments
1 task
…cognize-html-heading-in-no-missing-link-fragments
3 tasks
lumirlumir
commented
Feb 23, 2026
Member
Author
There was a problem hiding this comment.
Whitespace removal in the test cases was applied automatically by .editorconfig, and I've verified that this change has no side effects.
There was a problem hiding this comment.
Pull request overview
Fixes markdown/no-missing-link-fragments so link fragments can resolve to headings authored as raw HTML (<h1>–<h6>), matching GitHub’s slug behavior more closely (notably for headings containing non-slug characters like { } / emoji).
Changes:
- Add HTML heading detection in
no-missing-link-fragmentsby extracting<h1>–<h6>contents and slugging the plain-text equivalent. - Add extensive test coverage for HTML heading variations (case, whitespace, nested tags, attributes) and new invalid cases.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/rules/no-missing-link-fragments.js |
Adds regex-based extraction of HTML headings and strips nested tags before slugging. |
tests/rules/no-missing-link-fragments.test.js |
Adds many valid/invalid fixtures to ensure HTML headings are recognized and slugged as expected. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…' of https://github.com/eslint/markdown into fix-recognize-html-heading-in-no-missing-link-fragments
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prerequisites checklist
What is the purpose of this pull request?
In this PR, I've fixed the bug mentioned in #582.
Summary for #582: the issue in #582 was that the text inside
<h1>title</h1>needed to be interpreted as a valid slug id, but it wasn't. This PR fixes that.What changes did you make? (Give an overview)
I used two regex patterns,
htmlTagPatternandhtmlHeadingPattern, to extract the children ofh1–h6tags, then stripped any HTML tags from those children to obtain the proper text.These regexes were heavily inspired by the existing regex patterns that have been verified by many tests.
markdown/src/rules/no-html.js
Lines 27 to 28 in fba5d2f
markdown/src/rules/no-multiple-h1.js
Line 28 in fba5d2f
markdown/src/rules/require-alt-text.js
Line 28 in fba5d2f
(But these regex patterns also have some problems, so I've opened #624 to address this separately.)
Many test cases have been added to verify this behavior, and I've verified the generated slugs against GitHub's Markdown engine.
Related Issues
Fixes: #582
Is there anything you'd like reviewers to focus on?
Reference links: