-
-
Notifications
You must be signed in to change notification settings - Fork 757
/
Copy pathmd040.js
37 lines (32 loc) · 1.08 KB
/
md040.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
// @ts-check
"use strict";
const { addError, addErrorContext, filterTokens } = require("../helpers");
module.exports = {
"names": [ "MD040", "fenced-code-language" ],
"description": "Fenced code blocks should have a language specified",
"tags": [ "code", "language" ],
"function": function MD040(params, onError) {
let allowed = params.config.allowed_languages;
allowed = Array.isArray(allowed) ? allowed : [];
const languageOnly = !!params.config.language_only;
filterTokens(params, "fence", function forToken(token) {
const lang = token.info.trim().split(/\s+/u).shift();
if (lang === "") {
addErrorContext(onError, token.lineNumber, token.line);
} else if ((allowed.length > 0) && !allowed.includes(lang)) {
addError(
onError,
token.lineNumber,
`"${lang}" is not allowed`
);
}
if (languageOnly && (token.info !== lang)) {
addError(
onError,
token.lineNumber,
`Info string contains more than language: "${token.info}"`
);
}
});
}
};