mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 22:40:13 +01:00
Reimplement MD035/hr-style using micromark tokens (fixes #736).
This commit is contained in:
parent
f1e33672ba
commit
8057f3d37e
7 changed files with 508 additions and 25 deletions
20
lib/md035.js
20
lib/md035.js
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue