-
-
Notifications
You must be signed in to change notification settings - Fork 757
/
Copy pathmd033.js
66 lines (62 loc) · 2.05 KB
/
md033.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
57
58
59
60
61
62
63
64
65
66
// @ts-check
"use strict";
const { addError } = require("../helpers");
const { filterByTypes, getHtmlTagInfo, parse } =
require("../helpers/micromark.cjs");
const nextLinesRe = /[\r\n][\s\S]*$/;
module.exports = {
"names": [ "MD033", "no-inline-html" ],
"description": "Inline HTML",
"tags": [ "html" ],
"function": function MD033(params, onError) {
let allowedElements = params.config.allowed_elements;
allowedElements = Array.isArray(allowedElements) ? allowedElements : [];
allowedElements = allowedElements.map((element) => element.toLowerCase());
const pending = [ [ 0, params.parsers.micromark.tokens ] ];
let current = null;
while ((current = pending.shift())) {
const [ offset, tokens ] = current;
for (const token of filterByTypes(tokens, [ "htmlFlow", "htmlText" ])) {
if (token.type === "htmlText") {
const htmlTagInfo = getHtmlTagInfo(token);
if (
htmlTagInfo &&
!htmlTagInfo.close &&
!allowedElements.includes(htmlTagInfo.name.toLowerCase())
) {
const range = [
token.startColumn,
token.text.replace(nextLinesRe, "").length
];
addError(
onError,
token.startLine + offset,
"Element: " + htmlTagInfo.name,
undefined,
range
);
}
} else {
// token.type === "htmlFlow"
// Re-parse without "htmlFlow" to get only "htmlText" tokens
const options = {
"extensions": [
{
"disable": {
"null": [ "codeIndented", "htmlFlow" ]
}
}
]
};
// Use lines instead of token.text for accurate columns
const lines =
params.lines.slice(token.startLine - 1, token.endLine).join("\n");
const flowTokens = parse(lines, options);
pending.push(
[ token.startLine - 1, flowTokens ]
);
}
}
}
}
};