mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-24 01:40:13 +01:00
Convert markdownlint library to an ECMAScript module, replace markdownlint-micromark with micromark, stop publishing (large) markdownlint-browser.js, see https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c for guidance.
This commit is contained in:
parent
191226f070
commit
1e71f6f44e
140 changed files with 1087 additions and 10428 deletions
57
lib/md058.mjs
Normal file
57
lib/md058.mjs
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
// @ts-check
|
||||
|
||||
import { addErrorContext, isBlankLine } from "../helpers/helpers.cjs";
|
||||
import { getBlockQuotePrefixText } from "../helpers/micromark-helpers.cjs";
|
||||
import { filterByTypesCached } from "./cache.mjs";
|
||||
|
||||
/** @typedef {import("micromark-extension-gfm-table")} */
|
||||
|
||||
/** @type {import("./markdownlint.mjs").Rule} */
|
||||
export default {
|
||||
"names": [ "MD058", "blanks-around-tables" ],
|
||||
"description": "Tables should be surrounded by blank lines",
|
||||
"tags": [ "table" ],
|
||||
"parser": "micromark",
|
||||
"function": function MD058(params, onError) {
|
||||
const { lines } = params;
|
||||
const blockQuotePrefixes = filterByTypesCached([ "blockQuotePrefix", "linePrefix" ]);
|
||||
|
||||
// For every table...
|
||||
const tables = filterByTypesCached([ "table" ]);
|
||||
for (const table of tables) {
|
||||
|
||||
// Look for a blank line above the table
|
||||
const firstLineNumber = table.startLine;
|
||||
if (!isBlankLine(lines[firstLineNumber - 2])) {
|
||||
addErrorContext(
|
||||
onError,
|
||||
firstLineNumber,
|
||||
lines[firstLineNumber - 1].trim(),
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
{
|
||||
"insertText": getBlockQuotePrefixText(blockQuotePrefixes, firstLineNumber)
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// Look for a blank line below the table
|
||||
const lastLineNumber = table.endLine;
|
||||
if (!isBlankLine(lines[lastLineNumber])) {
|
||||
addErrorContext(
|
||||
onError,
|
||||
lastLineNumber,
|
||||
lines[lastLineNumber - 1].trim(),
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
{
|
||||
"lineNumber": lastLineNumber + 1,
|
||||
"insertText": getBlockQuotePrefixText(blockQuotePrefixes, lastLineNumber)
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue