mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 22:40:13 +01:00
Update MD005, MD007, MD022, MD037, MD038 to not report violations within "htmlFlow" context (fixes #999).
This commit is contained in:
parent
2a56f130c1
commit
63325edc97
15 changed files with 511 additions and 149 deletions
21
lib/md007.js
21
lib/md007.js
|
|
@ -3,12 +3,18 @@
|
|||
"use strict";
|
||||
|
||||
const { addErrorDetailIf } = require("../helpers");
|
||||
const { filterByTypes } = require("../helpers/micromark.cjs");
|
||||
const { filterByTypes, getTokenParentOfType, inHtmlFlow } =
|
||||
require("../helpers/micromark.cjs");
|
||||
|
||||
/**
|
||||
* @typedef {import("../helpers/micromark.cjs").Token} Token
|
||||
*/
|
||||
|
||||
const unorderedListTypes =
|
||||
[ "blockQuotePrefix", "listItemPrefix", "listUnordered" ];
|
||||
const unorderedParentTypes =
|
||||
[ "blockQuote", "listOrdered", "listUnordered" ];
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD007", "ul-indent" ],
|
||||
"description": "Unordered list indentation",
|
||||
|
|
@ -21,7 +27,7 @@ module.exports = {
|
|||
let lastBlockQuotePrefix = null;
|
||||
const tokens = filterByTypes(
|
||||
params.parsers.micromark.tokens,
|
||||
[ "blockQuotePrefix", "listItemPrefix", "listUnordered" ]
|
||||
unorderedListTypes
|
||||
);
|
||||
for (const token of tokens) {
|
||||
const { parent, startColumn, startLine, type } = token;
|
||||
|
|
@ -31,20 +37,21 @@ module.exports = {
|
|||
let nesting = 0;
|
||||
/** @type {Token | null} */
|
||||
let current = token;
|
||||
while ((current = current.parent)) {
|
||||
while (
|
||||
(current = getTokenParentOfType(current, unorderedParentTypes))
|
||||
) {
|
||||
if (current.type === "listUnordered") {
|
||||
nesting++;
|
||||
continue;
|
||||
} else if (current.type === "listOrdered") {
|
||||
nesting = -1;
|
||||
break;
|
||||
} else if (current.type === "blockQuote") {
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (nesting >= 0) {
|
||||
unorderedListNesting.set(token, nesting);
|
||||
}
|
||||
} else {
|
||||
} else if (!inHtmlFlow(token)) {
|
||||
// listItemPrefix
|
||||
const nesting = unorderedListNesting.get(parent);
|
||||
if (nesting !== undefined) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue