mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Reimplement MD046/code-block-style using micromark tokens.
This commit is contained in:
parent
4a7af239ce
commit
807fee01b1
2 changed files with 14 additions and 14 deletions
|
@ -5906,10 +5906,11 @@ module.exports = {
|
||||||
|
|
||||||
|
|
||||||
const { addErrorDetailIf } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js");
|
const { addErrorDetailIf } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js");
|
||||||
|
const { filterByTypes } = __webpack_require__(/*! ../helpers/micromark.cjs */ "../helpers/micromark.cjs");
|
||||||
|
|
||||||
const tokenTypeToStyle = {
|
const tokenTypeToStyle = {
|
||||||
"fence": "fenced",
|
"codeFenced": "fenced",
|
||||||
"code_block": "indented"
|
"codeIndented": "indented"
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -5918,17 +5919,16 @@ module.exports = {
|
||||||
"tags": [ "code" ],
|
"tags": [ "code" ],
|
||||||
"function": function MD046(params, onError) {
|
"function": function MD046(params, onError) {
|
||||||
let expectedStyle = String(params.config.style || "consistent");
|
let expectedStyle = String(params.config.style || "consistent");
|
||||||
const codeBlocksAndFences = params.parsers.markdownit.tokens.filter(
|
const codeBlocksAndFences =
|
||||||
(token) => (token.type === "code_block") || (token.type === "fence")
|
filterByTypes(params.parsers.micromark.tokens, [ "codeFenced", "codeIndented" ]);
|
||||||
);
|
|
||||||
for (const token of codeBlocksAndFences) {
|
for (const token of codeBlocksAndFences) {
|
||||||
const { lineNumber, type } = token;
|
const { startLine, type } = token;
|
||||||
if (expectedStyle === "consistent") {
|
if (expectedStyle === "consistent") {
|
||||||
expectedStyle = tokenTypeToStyle[type];
|
expectedStyle = tokenTypeToStyle[type];
|
||||||
}
|
}
|
||||||
addErrorDetailIf(
|
addErrorDetailIf(
|
||||||
onError,
|
onError,
|
||||||
lineNumber,
|
startLine,
|
||||||
expectedStyle,
|
expectedStyle,
|
||||||
tokenTypeToStyle[type]);
|
tokenTypeToStyle[type]);
|
||||||
}
|
}
|
||||||
|
|
14
lib/md046.js
14
lib/md046.js
|
@ -3,10 +3,11 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const { addErrorDetailIf } = require("../helpers");
|
const { addErrorDetailIf } = require("../helpers");
|
||||||
|
const { filterByTypes } = require("../helpers/micromark.cjs");
|
||||||
|
|
||||||
const tokenTypeToStyle = {
|
const tokenTypeToStyle = {
|
||||||
"fence": "fenced",
|
"codeFenced": "fenced",
|
||||||
"code_block": "indented"
|
"codeIndented": "indented"
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -15,17 +16,16 @@ module.exports = {
|
||||||
"tags": [ "code" ],
|
"tags": [ "code" ],
|
||||||
"function": function MD046(params, onError) {
|
"function": function MD046(params, onError) {
|
||||||
let expectedStyle = String(params.config.style || "consistent");
|
let expectedStyle = String(params.config.style || "consistent");
|
||||||
const codeBlocksAndFences = params.parsers.markdownit.tokens.filter(
|
const codeBlocksAndFences =
|
||||||
(token) => (token.type === "code_block") || (token.type === "fence")
|
filterByTypes(params.parsers.micromark.tokens, [ "codeFenced", "codeIndented" ]);
|
||||||
);
|
|
||||||
for (const token of codeBlocksAndFences) {
|
for (const token of codeBlocksAndFences) {
|
||||||
const { lineNumber, type } = token;
|
const { startLine, type } = token;
|
||||||
if (expectedStyle === "consistent") {
|
if (expectedStyle === "consistent") {
|
||||||
expectedStyle = tokenTypeToStyle[type];
|
expectedStyle = tokenTypeToStyle[type];
|
||||||
}
|
}
|
||||||
addErrorDetailIf(
|
addErrorDetailIf(
|
||||||
onError,
|
onError,
|
||||||
lineNumber,
|
startLine,
|
||||||
expectedStyle,
|
expectedStyle,
|
||||||
tokenTypeToStyle[type]);
|
tokenTypeToStyle[type]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue