Skip to content

feat: add no-multiple-h1 rule #377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

Pixel998
Copy link
Contributor

Prerequisites checklist

What is the purpose of this pull request?

This PR adds a new rule no-multiple-h1 to enforce at most one h1 heading in Markdown.

What changes did you make? (Give an overview)

Added the no-multiple-h1 rule, along with documentation and tests.

I decided to name it no-multiple-h1 instead to be more explicit about what the rule does.

Related Issues

Closes #373

Is there anything you'd like reviewers to focus on?

Copy link
Member

@lumirlumir lumirlumir left a comment

Choose a reason for hiding this comment

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

Currently, Markdownlint’s MD025 supports the title field in YAML front matter. It also provides an option to customize which field should be recognized as the valid H1 heading.

In contrast, @eslint/markdown supports both YAML and TOML front matter (while Markdownlint only supports YAML).

Given that, I think we should support the title field in both YAML and TOML front matter as valid H1 headings.

That’s my personal opinion — I’d love to hear what other team members think about supporting H1 detection from both YAML and TOML front matter, similar to how Markdownlint handles it.

@eslint/eslint-team


Also, we should support detecting <h1> HTML tags. The following code should trigger a warning:

<h1> Heading </h1>

# Heading

@nzakas
Copy link
Member

nzakas commented May 16, 2025

Currently, Markdownlint’s MD025 supports the title field in YAML front matter. It also provides an option to customize which field should be recognized as the valid H1 heading.

That seems reasonable to me. So if there's a frontmatter title then that counts as an H1. 👍

@github-project-automation github-project-automation bot moved this to Needs Triage in Triage May 17, 2025
@lumirlumir lumirlumir moved this from Needs Triage to Implementing in Triage May 17, 2025
@lumirlumir
Copy link
Member

lumirlumir commented May 21, 2025

---
hello: world # title: My Title
---
# Heading 1

Still a false positive when handling comments.

Should we introduce a YAML or TOML parser like yaml?

Using only regular expressions seems too fragile.

@Pixel998
Copy link
Contributor Author

Pixel998 commented May 21, 2025

@lumirlumir Do you have specific examples or edge cases in mind where regex parsing might fail?

@nzakas
Copy link
Member

nzakas commented May 21, 2025

Let's not introduce a parser. Rules shouldn't be doing parsing. If we can't accurately detect frontmatter H1s then let's leave it off this initial version.

@ntdiary

This comment was marked as off-topic.

@nzakas
Copy link
Member

nzakas commented May 23, 2025

@ntdiary please open a separate issue to request enhancements. We like to keep PRs focused on the original request.

Copy link
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!

Leaving it open for 2nd review.

@snitin315 snitin315 moved this from Implementing to Second Review Needed in Triage May 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Second Review Needed
Development

Successfully merging this pull request may close these issues.

New Rule: single-h1
5 participants