mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01:00
Update MD024/no-duplicate-heading to allow non-sibling duplicates (fixes #136).
This commit is contained in:
parent
4865301ce9
commit
d76ede1c4f
10 changed files with 246 additions and 15 deletions
18
lib/md024.js
18
lib/md024.js
|
|
@ -9,8 +9,24 @@ module.exports = {
|
|||
"description": "Multiple headings with the same content",
|
||||
"tags": [ "headings", "headers" ],
|
||||
"function": function MD024(params, onError) {
|
||||
const knownContent = [];
|
||||
const siblingsOnly = params.config.siblings_only ||
|
||||
params.config.allow_different_nesting || false;
|
||||
const knownContents = [ null, [] ];
|
||||
let lastLevel = 1;
|
||||
let knownContent = knownContents[lastLevel];
|
||||
shared.forEachHeading(params, function forHeading(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.indexOf(content) === -1) {
|
||||
knownContent.push(content);
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue