mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +01:00
Update MD040/fenced-code-language to add allowed_languages parameter (fixes #610).
This commit is contained in:
parent
c333976a44
commit
01ba757d3a
12 changed files with 199 additions and 9 deletions
|
|
@ -4152,16 +4152,25 @@ module.exports = {
|
|||
"use strict";
|
||||
// @ts-check
|
||||
|
||||
const { addErrorContext, filterTokens } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js");
|
||||
const { addError, addErrorContext, filterTokens } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js");
|
||||
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.map((lang) => lang.toLowerCase()) :
|
||||
[];
|
||||
filterTokens(params, "fence", function forToken(token) {
|
||||
if (!token.info.trim()) {
|
||||
const lang = token.info.trim();
|
||||
if (lang === "") {
|
||||
addErrorContext(onError, token.lineNumber, token.line);
|
||||
}
|
||||
else if (allowed.length > 0 &&
|
||||
!allowed.includes(lang.toLowerCase())) {
|
||||
addError(onError, token.lineNumber, `"${lang}" is not allowed`);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue