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 { filterByTypes } = __webpack_require__(/*! ../helpers/micromark.cjs */ "../helpers/micromark.cjs");
|
||||
|
||||
const tokenTypeToStyle = {
|
||||
"fence": "fenced",
|
||||
"code_block": "indented"
|
||||
"codeFenced": "fenced",
|
||||
"codeIndented": "indented"
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
|
@ -5918,17 +5919,16 @@ module.exports = {
|
|||
"tags": [ "code" ],
|
||||
"function": function MD046(params, onError) {
|
||||
let expectedStyle = String(params.config.style || "consistent");
|
||||
const codeBlocksAndFences = params.parsers.markdownit.tokens.filter(
|
||||
(token) => (token.type === "code_block") || (token.type === "fence")
|
||||
);
|
||||
const codeBlocksAndFences =
|
||||
filterByTypes(params.parsers.micromark.tokens, [ "codeFenced", "codeIndented" ]);
|
||||
for (const token of codeBlocksAndFences) {
|
||||
const { lineNumber, type } = token;
|
||||
const { startLine, type } = token;
|
||||
if (expectedStyle === "consistent") {
|
||||
expectedStyle = tokenTypeToStyle[type];
|
||||
}
|
||||
addErrorDetailIf(
|
||||
onError,
|
||||
lineNumber,
|
||||
startLine,
|
||||
expectedStyle,
|
||||
tokenTypeToStyle[type]);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue