mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10: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
|
|
@ -3,7 +3,7 @@
|
|||
"use strict";
|
||||
|
||||
const { addError, addErrorDetailIf } = require("../helpers");
|
||||
const { filterByTypes } = require("../helpers/micromark.cjs");
|
||||
const { filterByTypes, inHtmlFlow } = require("../helpers/micromark.cjs");
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD005", "list-indent" ],
|
||||
|
|
@ -13,7 +13,7 @@ module.exports = {
|
|||
const lists = filterByTypes(
|
||||
params.parsers.micromark.tokens,
|
||||
[ "listOrdered", "listUnordered" ]
|
||||
);
|
||||
).filter((list) => !inHtmlFlow(list));
|
||||
for (const list of lists) {
|
||||
const expectedIndent = list.startColumn - 1;
|
||||
let expectedEnd = 0;
|
||||
|
|
|
|||
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) {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
const { addErrorDetailIf, blockquotePrefixRe, isBlankLine } =
|
||||
require("../helpers");
|
||||
const { filterByTypes, getHeadingLevel } =
|
||||
const { filterByTypes, getHeadingLevel, inHtmlFlow } =
|
||||
require("../helpers/micromark.cjs");
|
||||
|
||||
const defaultLines = 1;
|
||||
|
|
@ -42,7 +42,7 @@ module.exports = {
|
|||
const headings = filterByTypes(
|
||||
parsers.micromark.tokens,
|
||||
[ "atxHeading", "setextHeading" ]
|
||||
);
|
||||
).filter((heading) => !inHtmlFlow(heading));
|
||||
for (const heading of headings) {
|
||||
const { startLine, endLine } = heading;
|
||||
const line = lines[startLine - 1].trim();
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
"use strict";
|
||||
|
||||
const { addError } = require("../helpers");
|
||||
const { filterByPredicate } = require("../helpers/micromark.cjs");
|
||||
const { filterByPredicate, inHtmlFlow } = require("../helpers/micromark.cjs");
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD037", "no-space-in-emphasis" ],
|
||||
|
|
@ -31,7 +31,7 @@ module.exports = {
|
|||
const { text, type } = child;
|
||||
if ((type === "data") && (text.length <= 3)) {
|
||||
const emphasisTokens = emphasisTokensByMarker.get(text);
|
||||
if (emphasisTokens) {
|
||||
if (emphasisTokens && !inHtmlFlow(child)) {
|
||||
emphasisTokens.push(child);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
12
lib/md038.js
12
lib/md038.js
|
|
@ -3,7 +3,8 @@
|
|||
"use strict";
|
||||
|
||||
const { addErrorContext } = require("../helpers");
|
||||
const { filterByTypes, tokenIfType } = require("../helpers/micromark.cjs");
|
||||
const { filterByTypes, inHtmlFlow, tokenIfType } =
|
||||
require("../helpers/micromark.cjs");
|
||||
|
||||
const leftSpaceRe = /^\s(?:[^`]|$)/;
|
||||
const rightSpaceRe = /[^`]\s$/;
|
||||
|
|
@ -23,10 +24,11 @@ module.exports = {
|
|||
"description": "Spaces inside code span elements",
|
||||
"tags": [ "whitespace", "code" ],
|
||||
"function": function MD038(params, onError) {
|
||||
const codeTextTokens =
|
||||
filterByTypes(params.parsers.micromark.tokens, [ "codeText" ]);
|
||||
for (const token of codeTextTokens) {
|
||||
const { children } = token;
|
||||
const codeTexts =
|
||||
filterByTypes(params.parsers.micromark.tokens, [ "codeText" ])
|
||||
.filter((codeText) => !inHtmlFlow(codeText));
|
||||
for (const codeText of codeTexts) {
|
||||
const { children } = codeText;
|
||||
const first = 0;
|
||||
const last = children.length - 1;
|
||||
const startSequence = tokenIfType(children[first], "codeTextSequence");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue