Update MD024/no-duplicate-heading to allow non-sibling duplicates (fixes #136).

This commit is contained in:
David Anson 2018-07-19 21:49:30 -07:00
parent 4865301ce9
commit d76ede1c4f
10 changed files with 246 additions and 15 deletions

View file

@ -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 {