forked from mui/material-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathduplicate-h1.js
31 lines (30 loc) · 1.11 KB
/
duplicate-h1.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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;
}
}
});
},
};