forked from mui/material-ui
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[blog] Lint duplicate h1 on the page (mui#40835)
- Loading branch information
1 parent
a9f1a4c
commit 2b751cf
Showing
2 changed files
with
34 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// This rule is an extension of MD025/no-multiple-top-level-headings. | ||
// The rule is buggy https://github.com/DavidAnson/markdownlint/pull/1109 | ||
// but also blog headers don't tell you that h1 is already injected. | ||
module.exports = { | ||
names: ['duplicateH1'], | ||
description: 'Multiple top-level headings in the same document.', | ||
tags: ['headings'], | ||
function: (params, onError) => { | ||
let hasTopLevelHeading = false; | ||
params.tokens.forEach((token) => { | ||
if (token.type === 'heading_open' && token.tag === 'h1') { | ||
// Avoid duplicate errors with MD025. | ||
if (hasTopLevelHeading !== false && hasTopLevelHeading !== 1) { | ||
onError({ | ||
lineNumber: token.lineNumber, | ||
}); | ||
} else if (params.name.includes('/docs/pages/blog/')) { | ||
onError({ | ||
lineNumber: token.lineNumber, | ||
details: 'In the blog, the h1 is already added using the markdown header.title value.', | ||
}); | ||
} | ||
|
||
// Store the first h1 of the page. | ||
if (hasTopLevelHeading === false) { | ||
hasTopLevelHeading = token.lineNumber; | ||
} | ||
} | ||
}); | ||
}, | ||
}; |