mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01:00
Exclude htmlFlow content by default for filterByTypes, opt in as needed.
This commit is contained in:
parent
ea9659841e
commit
12502f6571
18 changed files with 206 additions and 129 deletions
|
|
@ -3,7 +3,7 @@
|
|||
"use strict";
|
||||
|
||||
const { addErrorDetailIf } = require("../helpers");
|
||||
const { filterByTypes, getHeadingLevel, getHeadingStyle, inHtmlFlow } =
|
||||
const { filterByTypes, getHeadingLevel, getHeadingStyle } =
|
||||
require("../helpers/micromark.cjs");
|
||||
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
|
|
@ -24,7 +24,7 @@ module.exports = {
|
|||
if (style === "consistent") {
|
||||
style = styleForToken;
|
||||
}
|
||||
if ((styleForToken !== style) && !inHtmlFlow(heading)) {
|
||||
if (styleForToken !== style) {
|
||||
const h12 = getHeadingLevel(heading) <= 2;
|
||||
const setextWithAtx =
|
||||
(style === "setext_with_atx") &&
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
"use strict";
|
||||
|
||||
const { addError, addErrorDetailIf } = require("../helpers");
|
||||
const { filterByTypes, inHtmlFlow } = require("../helpers/micromark.cjs");
|
||||
const { filterByTypes } = require("../helpers/micromark.cjs");
|
||||
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("./markdownlint").Rule */
|
||||
|
|
@ -21,7 +21,7 @@ module.exports = {
|
|||
const lists = filterByTypes(
|
||||
micromarkTokens,
|
||||
[ "listOrdered", "listUnordered" ]
|
||||
).filter((list) => !inHtmlFlow(list));
|
||||
);
|
||||
for (const list of lists) {
|
||||
const expectedIndent = list.startColumn - 1;
|
||||
let expectedEnd = 0;
|
||||
|
|
@ -38,8 +38,8 @@ module.exports = {
|
|||
lineNumber,
|
||||
expectedIndent,
|
||||
actualIndent,
|
||||
null,
|
||||
null,
|
||||
undefined,
|
||||
undefined,
|
||||
range
|
||||
// No fixInfo; MD007 handles this scenario better
|
||||
);
|
||||
|
|
|
|||
|
|
@ -3,8 +3,7 @@
|
|||
"use strict";
|
||||
|
||||
const { addErrorDetailIf } = require("../helpers");
|
||||
const { filterByTypes, getTokenParentOfType, inHtmlFlow } =
|
||||
require("../helpers/micromark.cjs");
|
||||
const { filterByTypes, getTokenParentOfType } = require("../helpers/micromark.cjs");
|
||||
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("markdownlint-micromark").TokenType[] */
|
||||
|
|
@ -57,7 +56,7 @@ module.exports = {
|
|||
if (nesting >= 0) {
|
||||
unorderedListNesting.set(token, nesting);
|
||||
}
|
||||
} else if (!inHtmlFlow(token)) {
|
||||
} else {
|
||||
// listItemPrefix
|
||||
const nesting = unorderedListNesting.get(parent);
|
||||
if (nesting !== undefined) {
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@
|
|||
|
||||
const { addErrorDetailIf, blockquotePrefixRe, isBlankLine } =
|
||||
require("../helpers");
|
||||
const { filterByTypes, getHeadingLevel, inHtmlFlow } =
|
||||
require("../helpers/micromark.cjs");
|
||||
const { filterByTypes, getHeadingLevel } = require("../helpers/micromark.cjs");
|
||||
|
||||
const defaultLines = 1;
|
||||
|
||||
|
|
@ -50,7 +49,7 @@ module.exports = {
|
|||
const headings = filterByTypes(
|
||||
micromarkTokens,
|
||||
[ "atxHeading", "setextHeading" ]
|
||||
).filter((heading) => !inHtmlFlow(heading));
|
||||
);
|
||||
for (const heading of headings) {
|
||||
const { startLine, endLine } = heading;
|
||||
const line = lines[startLine - 1].trim();
|
||||
|
|
@ -73,7 +72,7 @@ module.exports = {
|
|||
actualAbove,
|
||||
"Above",
|
||||
line,
|
||||
null,
|
||||
undefined,
|
||||
{
|
||||
"insertText": getBlockQuote(
|
||||
lines[startLine - 2],
|
||||
|
|
@ -101,7 +100,7 @@ module.exports = {
|
|||
actualBelow,
|
||||
"Below",
|
||||
line,
|
||||
null,
|
||||
undefined,
|
||||
{
|
||||
"lineNumber": endLine + 1,
|
||||
"insertText": getBlockQuote(
|
||||
|
|
|
|||
|
|
@ -3,8 +3,7 @@
|
|||
"use strict";
|
||||
|
||||
const { addErrorContext, frontMatterHasTitle } = require("../helpers");
|
||||
const { filterByTypes, getHeadingLevel, inHtmlFlow } =
|
||||
require("../helpers/micromark.cjs");
|
||||
const { filterByTypes, getHeadingLevel } = require("../helpers/micromark.cjs");
|
||||
|
||||
// eslint-disable-next-line jsdoc/valid-types
|
||||
/** @type import("./markdownlint").Rule */
|
||||
|
|
@ -27,7 +26,7 @@ module.exports = {
|
|||
);
|
||||
for (const heading of headings) {
|
||||
const headingLevel = getHeadingLevel(heading);
|
||||
if ((headingLevel === level) && !inHtmlFlow(heading)) {
|
||||
if (headingLevel === level) {
|
||||
if (hasTopLevelHeading || foundFrontMatterTitle) {
|
||||
const headingTexts = filterByTypes(
|
||||
heading.children,
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ module.exports = {
|
|||
const micromarkTokens =
|
||||
// @ts-ignore
|
||||
params.parsers.micromark.tokens;
|
||||
for (const token of filterByTypes(micromarkTokens, [ "htmlText" ])) {
|
||||
for (const token of filterByTypes(micromarkTokens, [ "htmlText" ], true)) {
|
||||
const htmlTagInfo = getHtmlTagInfo(token);
|
||||
if (
|
||||
htmlTagInfo &&
|
||||
|
|
|
|||
|
|
@ -94,8 +94,8 @@ module.exports = {
|
|||
onError,
|
||||
token.startLine,
|
||||
token.text,
|
||||
null,
|
||||
null,
|
||||
undefined,
|
||||
undefined,
|
||||
range,
|
||||
fixInfo
|
||||
);
|
||||
|
|
|
|||
|
|
@ -3,8 +3,7 @@
|
|||
"use strict";
|
||||
|
||||
const { addErrorContext } = require("../helpers");
|
||||
const { filterByTypes, inHtmlFlow, tokenIfType } =
|
||||
require("../helpers/micromark.cjs");
|
||||
const { filterByTypes, tokenIfType } = require("../helpers/micromark.cjs");
|
||||
|
||||
const leftSpaceRe = /^\s(?:[^`]|$)/;
|
||||
const rightSpaceRe = /[^`]\s$/;
|
||||
|
|
@ -32,8 +31,7 @@ module.exports = {
|
|||
const micromarkTokens =
|
||||
// @ts-ignore
|
||||
params.parsers.micromark.tokens;
|
||||
const codeTexts = filterByTypes(micromarkTokens, [ "codeText" ])
|
||||
.filter((codeText) => !inHtmlFlow(codeText));
|
||||
const codeTexts = filterByTypes(micromarkTokens, [ "codeText" ]);
|
||||
for (const codeText of codeTexts) {
|
||||
const { children } = codeText;
|
||||
const first = 0;
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ module.exports = {
|
|||
if ((token.type === "atxHeading") || (token.type === "setextHeading")) {
|
||||
isError = (getHeadingLevel(token) !== level);
|
||||
} else if (token.type === "htmlFlow") {
|
||||
const htmlTexts = filterByTypes(token.children, [ "htmlText" ]);
|
||||
const htmlTexts = filterByTypes(token.children, [ "htmlText" ], true);
|
||||
const tagInfo = (htmlTexts.length > 0) && getHtmlTagInfo(htmlTexts[0]);
|
||||
isError = !tagInfo || (tagInfo.name.toLowerCase() !== `h${level}`);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ module.exports = {
|
|||
}
|
||||
|
||||
// Process HTML images
|
||||
const htmlTexts = filterByTypes(micromarkTokens, [ "htmlText" ]);
|
||||
const htmlTexts = filterByTypes(micromarkTokens, [ "htmlText" ], true);
|
||||
for (const htmlText of htmlTexts) {
|
||||
const { startColumn, startLine, text } = htmlText;
|
||||
const htmlTagInfo = getHtmlTagInfo(htmlText);
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ module.exports = {
|
|||
}
|
||||
|
||||
// Process HTML anchors
|
||||
for (const token of filterByTypes(micromarkTokens, [ "htmlText" ])) {
|
||||
for (const token of filterByTypes(micromarkTokens, [ "htmlText" ], true)) {
|
||||
const htmlTagInfo = getHtmlTagInfo(token);
|
||||
if (htmlTagInfo && !htmlTagInfo.close) {
|
||||
const anchorMatch = idRe.exec(token.text) ||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue