mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01:00
Reimplement MD028/no-blanks-blockquote using micromark tokens.
This commit is contained in:
parent
89eef68dbd
commit
f5b5773b50
4 changed files with 94 additions and 30 deletions
|
|
@ -6,7 +6,6 @@ const { addError, allPunctuationNoQuestion, endOfLineGemojiCodeRe,
|
|||
endOfLineHtmlEntityRe, escapeForRegExp } = require("../helpers");
|
||||
const { filterByTypes } = require("../helpers/micromark.cjs");
|
||||
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD026", "no-trailing-punctuation" ],
|
||||
"description": "Trailing punctuation in heading",
|
||||
|
|
|
|||
38
lib/md028.js
38
lib/md028.js
|
|
@ -3,28 +3,38 @@
|
|||
"use strict";
|
||||
|
||||
const { addError } = require("../helpers");
|
||||
const { getSiblingLists } = require("../helpers/micromark.cjs");
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD028", "no-blanks-blockquote" ],
|
||||
"description": "Blank line inside blockquote",
|
||||
"tags": [ "blockquote", "whitespace" ],
|
||||
"function": function MD028(params, onError) {
|
||||
let prevToken = {};
|
||||
let prevLineNumber = null;
|
||||
for (const token of params.parsers.markdownit.tokens) {
|
||||
if ((token.type === "blockquote_open") &&
|
||||
(prevToken.type === "blockquote_close")) {
|
||||
for (
|
||||
let lineNumber = prevLineNumber;
|
||||
lineNumber < token.lineNumber;
|
||||
lineNumber++) {
|
||||
addError(onError, lineNumber);
|
||||
for (const siblings of getSiblingLists(params.parsers.micromark.tokens)) {
|
||||
let errorLineNumbers = null;
|
||||
for (const sibling of siblings) {
|
||||
switch (sibling.type) {
|
||||
case "blockQuote":
|
||||
for (const lineNumber of (errorLineNumbers || [])) {
|
||||
addError(onError, lineNumber);
|
||||
}
|
||||
errorLineNumbers = [];
|
||||
break;
|
||||
case "lineEnding":
|
||||
case "linePrefix":
|
||||
case "listItemIndent":
|
||||
// Ignore
|
||||
break;
|
||||
case "lineEndingBlank":
|
||||
if (errorLineNumbers) {
|
||||
errorLineNumbers.push(sibling.startLine);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
errorLineNumbers = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
prevToken = token;
|
||||
if (token.type === "blockquote_open") {
|
||||
prevLineNumber = token.map[1] + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue