Reimplement MD035/hr-style using micromark tokens (fixes #736).

This commit is contained in:
David Anson 2023-03-06 21:38:40 -08:00
parent f1e33672ba
commit 8057f3d37e
7 changed files with 508 additions and 25 deletions

View file

@ -2,7 +2,8 @@
"use strict";
const { addErrorDetailIf, filterTokens } = require("../helpers");
const { addErrorDetailIf } = require("../helpers");
const { filterByTypes } = require("../helpers/micromark.cjs");
module.exports = {
"names": [ "MD035", "hr-style" ],
@ -10,17 +11,14 @@ module.exports = {
"tags": [ "hr" ],
"function": function MD035(params, onError) {
let style = String(params.config.style || "consistent").trim();
filterTokens(params, "hr", (token) => {
const { line, lineNumber } = token;
let { markup } = token;
const match = line.match(/[_*\-\s]+$/);
if (match) {
markup = match[0].trim();
}
const thematicBreaks =
filterByTypes(params.parsers.micromark.tokens, [ "thematicBreak" ]);
for (const token of thematicBreaks) {
const { startLine, text } = token;
if (style === "consistent") {
style = markup;
style = text;
}
addErrorDetailIf(onError, lineNumber, style, markup);
});
addErrorDetailIf(onError, startLine, style, text);
}
}
};