forked from DavidAnson/markdownlint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmd024.js
38 lines (35 loc) · 1.14 KB
/
md024.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
32
33
34
35
36
37
38
// @ts-check
"use strict";
const { addErrorContext, forEachHeading } = require("../helpers");
module.exports = {
"names": [ "MD024", "no-duplicate-heading", "no-duplicate-header" ],
"description": "Multiple headings with the same content",
"tags": [ "headings", "headers" ],
"function": function MD024(params, onError) {
const siblingsOnly = !!params.config.siblings_only ||
!!params.config.allow_different_nesting || false;
const knownContents = [ null, [] ];
let lastLevel = 1;
let knownContent = knownContents[lastLevel];
forEachHeading(params, (heading, content) => {
if (siblingsOnly) {
const newLevel = heading.tag.slice(1);
while (lastLevel < newLevel) {
lastLevel++;
knownContents[lastLevel] = [];
}
while (lastLevel > newLevel) {
knownContents[lastLevel] = [];
lastLevel--;
}
knownContent = knownContents[newLevel];
}
if (knownContent.includes(content)) {
addErrorContext(onError, heading.lineNumber,
heading.line.trim());
} else {
knownContent.push(content);
}
});
}
};