-
-
Notifications
You must be signed in to change notification settings - Fork 757
/
Copy pathmd036.js
56 lines (53 loc) · 1.84 KB
/
md036.js
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
// @ts-check
"use strict";
const { addErrorContext, allPunctuation } = require("../helpers");
module.exports = {
"names": [ "MD036", "no-emphasis-as-heading", "no-emphasis-as-header" ],
"description": "Emphasis used instead of a heading",
"tags": [ "headings", "headers", "emphasis" ],
"function": function MD036(params, onError) {
let punctuation = params.config.punctuation;
punctuation =
String((punctuation === undefined) ? allPunctuation : punctuation);
const re = new RegExp("[" + punctuation + "]$");
// eslint-disable-next-line jsdoc/require-jsdoc
function base(token) {
if (token.type === "paragraph_open") {
return function inParagraph(t) {
// Always paragraph_open/inline/paragraph_close,
const children = t.children.filter(function notEmptyText(child) {
return (child.type !== "text") || (child.content !== "");
});
if ((children.length === 3) &&
((children[0].type === "strong_open") ||
(children[0].type === "em_open")) &&
(children[1].type === "text") &&
!re.test(children[1].content)) {
addErrorContext(onError, t.lineNumber,
children[1].content);
}
return base;
};
} else if (token.type === "blockquote_open") {
return function inBlockquote(t) {
if (t.type !== "blockquote_close") {
return inBlockquote;
}
return base;
};
} else if (token.type === "list_item_open") {
return function inListItem(t) {
if (t.type !== "list_item_close") {
return inListItem;
}
return base;
};
}
return base;
}
let state = base;
for (const token of params.parsers.markdownit.tokens) {
state = state(token);
}
}
};