mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 14:00:13 +01:00
Enable custom rules to use the micromark parser, export micromark helpers for reuse.
This commit is contained in:
parent
264da24dae
commit
5cc40c54b7
16 changed files with 4109 additions and 113 deletions
|
|
@ -2,26 +2,54 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
/** @type import("../../lib/markdownlint").Rule */
|
||||
module.exports = {
|
||||
"names": [ "any-blockquote" ],
|
||||
"description": "Rule that reports an error for any blockquote",
|
||||
"information": new URL(
|
||||
"https://github.com/DavidAnson/markdownlint" +
|
||||
"/blob/main/test/rules/any-blockquote.js"
|
||||
),
|
||||
"tags": [ "test" ],
|
||||
"parser": "markdownit",
|
||||
"function": (params, onError) => {
|
||||
const blockquotes = params.parsers.markdownit.tokens
|
||||
.filter(((token) => token.type === "blockquote_open"));
|
||||
for (const blockquote of blockquotes) {
|
||||
const lines = blockquote.map[1] - blockquote.map[0];
|
||||
onError({
|
||||
"lineNumber": blockquote.lineNumber,
|
||||
"detail": "Blockquote spans " + lines + " line(s).",
|
||||
"context": blockquote.line.substr(0, 7)
|
||||
});
|
||||
/** @type import("../../lib/markdownlint").Rule[] */
|
||||
module.exports = [
|
||||
|
||||
// micromark parser (preferred)
|
||||
{
|
||||
"names": [ "any-blockquote-micromark" ],
|
||||
"description": "Rule that reports an error for any blockquote",
|
||||
"information": new URL(
|
||||
"https://github.com/DavidAnson/markdownlint/blob/main/test/rules/any-blockquote.js"
|
||||
),
|
||||
"tags": [ "test" ],
|
||||
"parser": "micromark",
|
||||
"function": (params, onError) => {
|
||||
const blockquotes = params.parsers.micromark.tokens
|
||||
.filter(((token) => token.type === "blockQuote"));
|
||||
for (const blockquote of blockquotes) {
|
||||
const lines = blockquote.endLine - blockquote.startLine + 1;
|
||||
onError({
|
||||
"lineNumber": blockquote.startLine,
|
||||
"detail": "Blockquote spans " + lines + " line(s).",
|
||||
"context": params.lines[blockquote.startLine - 1]
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// markdown-it parser (legacy)
|
||||
{
|
||||
"names": [ "any-blockquote-markdown-it" ],
|
||||
"description": "Rule that reports an error for any blockquote",
|
||||
"information": new URL(
|
||||
"https://github.com/DavidAnson/markdownlint/blob/main/test/rules/any-blockquote.js"
|
||||
),
|
||||
"tags": [ "test" ],
|
||||
"parser": "markdownit",
|
||||
"function": (params, onError) => {
|
||||
const blockquotes = params.parsers.markdownit.tokens
|
||||
.filter(((token) => token.type === "blockquote_open"));
|
||||
for (const blockquote of blockquotes) {
|
||||
const [ startIndex, endIndex ] = blockquote.map;
|
||||
const lines = endIndex - startIndex;
|
||||
onError({
|
||||
"lineNumber": blockquote.lineNumber,
|
||||
"detail": "Blockquote spans " + lines + " line(s).",
|
||||
"context": blockquote.line
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
];
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ const validateJson = require("./validate-json");
|
|||
module.exports.validateJson = validateJson;
|
||||
|
||||
module.exports.all = [
|
||||
anyBlockquote,
|
||||
...anyBlockquote,
|
||||
everyNLines,
|
||||
firstLine,
|
||||
lettersEX,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue