Skip to content

fix: recognize HTML heading in no-missing-link-fragments#583

Merged
snitin315 merged 23 commits intomainfrom
fix-recognize-html-heading-in-no-missing-link-fragments
Mar 16, 2026
Merged

fix: recognize HTML heading in no-missing-link-fragments#583
snitin315 merged 23 commits intomainfrom
fix-recognize-html-heading-in-no-missing-link-fragments

Conversation

@lumirlumir
Copy link
Copy Markdown
Member

@lumirlumir lumirlumir commented Nov 12, 2025

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, htmlTagPattern and htmlHeadingPattern, to extract the children of h1h6 tags, 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.

const htmlTagPattern =
/<(?<tagName>[a-z0-9]+(?:-[a-z0-9]+)*)(?:\s(?:[^>"']|"[^"]*"|'[^']*')*)?\/?>/giu;

const h1TagPattern = /<h1[^>]*>[\s\S]*?<\/h1>/giu;

const imgTagPattern = /<img(?:\s(?:[^>"']|"[^"]*"|'[^']*')*)?\/?>/giu;

(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:

@eslintbot eslintbot added this to Triage Nov 12, 2025
@github-project-automation github-project-automation Bot moved this to Needs Triage in Triage Nov 12, 2025
@nzakas nzakas moved this from Needs Triage to Implementing in Triage Nov 18, 2025
@github-actions

This comment was marked as resolved.

…cognize-html-heading-in-no-missing-link-fragments
@lumirlumir lumirlumir moved this from Implementing to Needs Triage in Triage Feb 23, 2026
@lumirlumir lumirlumir marked this pull request as ready for review February 23, 2026 09:17
Copilot AI review requested due to automatic review settings February 23, 2026 09:17
Copy link
Copy Markdown
Member Author

@lumirlumir lumirlumir Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whitespace removal in the test cases was applied automatically by .editorconfig, and I've verified that this change has no side effects.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-fragments by 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.

Comment thread src/rules/no-missing-link-fragments.js Outdated
Comment thread src/rules/no-missing-link-fragments.js
Comment thread tests/rules/no-missing-link-fragments.test.js Outdated
@lumirlumir lumirlumir marked this pull request as draft February 26, 2026 13:01
@lumirlumir lumirlumir marked this pull request as ready for review February 26, 2026 14:10
Copy link
Copy Markdown
Contributor

@snitin315 snitin315 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@snitin315 snitin315 moved this from Needs Triage to Implementing in Triage Mar 16, 2026
@snitin315 snitin315 merged commit bd9dfa3 into main Mar 16, 2026
44 of 48 checks passed
@snitin315 snitin315 deleted the fix-recognize-html-heading-in-no-missing-link-fragments branch March 16, 2026 14:59
@github-project-automation github-project-automation Bot moved this from Implementing to Complete in Triage Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Complete

Development

Successfully merging this pull request may close these issues.

Bug: false markdown/no-missing-link-fragments positive

5 participants