mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Refactor to move reparse of micromark htmlFlow token content into core micromarkParse implementation for simplicity and sharing.
This commit is contained in:
parent
9646590496
commit
e86fb7699d
11 changed files with 307 additions and 84 deletions
27
lib/md033.js
27
lib/md033.js
|
@ -3,8 +3,7 @@
|
|||
"use strict";
|
||||
|
||||
const { addError } = require("../helpers");
|
||||
const { filterByTypes, getHtmlTagInfo, parse } =
|
||||
require("../helpers/micromark.cjs");
|
||||
const { filterByTypes, getHtmlTagInfo } = require("../helpers/micromark.cjs");
|
||||
|
||||
const nextLinesRe = /[\r\n][\s\S]*$/;
|
||||
|
||||
|
@ -16,10 +15,10 @@ module.exports = {
|
|||
let allowedElements = params.config.allowed_elements;
|
||||
allowedElements = Array.isArray(allowedElements) ? allowedElements : [];
|
||||
allowedElements = allowedElements.map((element) => element.toLowerCase());
|
||||
const pending = [ [ 0, params.parsers.micromark.tokens ] ];
|
||||
const pending = [ params.parsers.micromark.tokens ];
|
||||
let current = null;
|
||||
while ((current = pending.shift())) {
|
||||
const [ offset, tokens ] = current;
|
||||
const tokens = current;
|
||||
for (const token of filterByTypes(tokens, [ "htmlFlow", "htmlText" ])) {
|
||||
if (token.type === "htmlText") {
|
||||
const htmlTagInfo = getHtmlTagInfo(token);
|
||||
|
@ -34,7 +33,7 @@ module.exports = {
|
|||
];
|
||||
addError(
|
||||
onError,
|
||||
token.startLine + offset,
|
||||
token.startLine,
|
||||
"Element: " + htmlTagInfo.name,
|
||||
undefined,
|
||||
range
|
||||
|
@ -42,23 +41,7 @@ module.exports = {
|
|||
}
|
||||
} else {
|
||||
// token.type === "htmlFlow"
|
||||
// Re-parse without "htmlFlow" to get only "htmlText" tokens
|
||||
const options = {
|
||||
"extensions": [
|
||||
{
|
||||
"disable": {
|
||||
"null": [ "codeIndented", "htmlFlow" ]
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
// Use lines instead of token.text for accurate columns
|
||||
const lines =
|
||||
params.lines.slice(token.startLine - 1, token.endLine).join("\n");
|
||||
const flowTokens = parse(lines, options);
|
||||
pending.push(
|
||||
[ token.startLine - 1, flowTokens ]
|
||||
);
|
||||
pending.push(token.htmlFlowChildren);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue