-
-
Notifications
You must be signed in to change notification settings - Fork 746
/
Copy pathmd058.mjs
57 lines (51 loc) · 1.7 KB
/
md058.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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").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)
}
);
}
}
}
};