mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-22 17:00:13 +01:00
Reimplement MD051/link-fragments using micromark tokens, report reference link issues for definition and fix when possible, handle reporting multiple violations on the same line better.
This commit is contained in:
parent
dd73b0ad7f
commit
ef1bd286a9
14 changed files with 458 additions and 346 deletions
49
lib/md033.js
49
lib/md033.js
|
|
@ -3,7 +3,8 @@
|
|||
"use strict";
|
||||
|
||||
const { addError } = require("../helpers");
|
||||
const { filterByTypes, getHtmlTagInfo } = require("../helpers/micromark.cjs");
|
||||
const { filterByHtmlTokens, getHtmlTagInfo } =
|
||||
require("../helpers/micromark.cjs");
|
||||
|
||||
const nextLinesRe = /[\r\n][\s\S]*$/;
|
||||
|
||||
|
|
@ -15,34 +16,24 @@ module.exports = {
|
|||
let allowedElements = params.config.allowed_elements;
|
||||
allowedElements = Array.isArray(allowedElements) ? allowedElements : [];
|
||||
allowedElements = allowedElements.map((element) => element.toLowerCase());
|
||||
const pending = [ params.parsers.micromark.tokens ];
|
||||
let current = null;
|
||||
while ((current = pending.shift())) {
|
||||
const tokens = current;
|
||||
for (const token of filterByTypes(tokens, [ "htmlFlow", "htmlText" ])) {
|
||||
if (token.type === "htmlText") {
|
||||
const htmlTagInfo = getHtmlTagInfo(token);
|
||||
if (
|
||||
htmlTagInfo &&
|
||||
!htmlTagInfo.close &&
|
||||
!allowedElements.includes(htmlTagInfo.name.toLowerCase())
|
||||
) {
|
||||
const range = [
|
||||
token.startColumn,
|
||||
token.text.replace(nextLinesRe, "").length
|
||||
];
|
||||
addError(
|
||||
onError,
|
||||
token.startLine,
|
||||
"Element: " + htmlTagInfo.name,
|
||||
undefined,
|
||||
range
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// token.type === "htmlFlow"
|
||||
pending.push(token.htmlFlowChildren);
|
||||
}
|
||||
for (const token of filterByHtmlTokens(params.parsers.micromark.tokens)) {
|
||||
const htmlTagInfo = getHtmlTagInfo(token);
|
||||
if (
|
||||
htmlTagInfo &&
|
||||
!htmlTagInfo.close &&
|
||||
!allowedElements.includes(htmlTagInfo.name.toLowerCase())
|
||||
) {
|
||||
const range = [
|
||||
token.startColumn,
|
||||
token.text.replace(nextLinesRe, "").length
|
||||
];
|
||||
addError(
|
||||
onError,
|
||||
token.startLine,
|
||||
"Element: " + htmlTagInfo.name,
|
||||
undefined,
|
||||
range
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue