-
-
Notifications
You must be signed in to change notification settings - Fork 746
/
Copy pathmd003.mjs
47 lines (45 loc) · 1.62 KB
/
md003.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
// @ts-check
import { addErrorDetailIf } from "../helpers/helpers.cjs";
import { getHeadingLevel, getHeadingStyle } from "../helpers/micromark-helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";
/** @type {import("markdownlint").Rule} */
export default {
"names": [ "MD003", "heading-style" ],
"description": "Heading style",
"tags": [ "headings" ],
"parser": "micromark",
"function": function MD003(params, onError) {
let style = String(params.config.style || "consistent");
for (const heading of filterByTypesCached([ "atxHeading", "setextHeading" ])) {
const styleForToken = getHeadingStyle(heading);
if (style === "consistent") {
style = styleForToken;
}
if (styleForToken !== style) {
const h12 = getHeadingLevel(heading) <= 2;
const setextWithAtx =
(style === "setext_with_atx") &&
((h12 && (styleForToken === "setext")) ||
(!h12 && (styleForToken === "atx")));
const setextWithAtxClosed =
(style === "setext_with_atx_closed") &&
((h12 && (styleForToken === "setext")) ||
(!h12 && (styleForToken === "atx_closed")));
if (!setextWithAtx && !setextWithAtxClosed) {
let expected = style;
if (style === "setext_with_atx") {
expected = h12 ? "setext" : "atx";
} else if (style === "setext_with_atx_closed") {
expected = h12 ? "setext" : "atx_closed";
}
addErrorDetailIf(
onError,
heading.startLine,
expected,
styleForToken
);
}
}
}
}
};