mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-24 01:40:13 +01:00
Add includesSorted function, use for faster searches of sorted arrays.
This commit is contained in:
parent
d7c0d195d7
commit
9b9532e163
8 changed files with 86 additions and 50 deletions
31
lib/md033.js
31
lib/md033.js
|
|
@ -3,6 +3,9 @@
|
|||
"use strict";
|
||||
|
||||
const shared = require("./shared");
|
||||
const {
|
||||
addError, filterTokens, forEachInlineChild, newLineRe, rangeFromRegExp
|
||||
} = shared;
|
||||
|
||||
const htmlRe = /<[^>]*>/;
|
||||
|
||||
|
|
@ -12,30 +15,22 @@ module.exports = {
|
|||
"tags": [ "html" ],
|
||||
"function": function MD033(params, onError) {
|
||||
const allowedElements = (params.config.allowed_elements || [])
|
||||
.map(function forElement(element) {
|
||||
return element.toLowerCase();
|
||||
});
|
||||
.map((element) => element.toLowerCase());
|
||||
function forToken(token) {
|
||||
token.content.split(shared.newLineRe)
|
||||
.forEach(function forLine(line, offset) {
|
||||
token.content.split(newLineRe)
|
||||
.forEach((line, offset) => {
|
||||
const allowed = (line.match(/<[^/\s>!]*/g) || [])
|
||||
.filter(function forElement(element) {
|
||||
return element.length > 1;
|
||||
})
|
||||
.map(function forElement(element) {
|
||||
return element.slice(1).toLowerCase();
|
||||
})
|
||||
.filter(function forElement(element) {
|
||||
return allowedElements.indexOf(element) === -1;
|
||||
});
|
||||
.filter((element) => element.length > 1)
|
||||
.map((element) => element.slice(1).toLowerCase())
|
||||
.filter((element) => !allowedElements.includes(element));
|
||||
if (allowed.length) {
|
||||
shared.addError(onError, token.lineNumber + offset,
|
||||
addError(onError, token.lineNumber + offset,
|
||||
"Element: " + allowed[0], null,
|
||||
shared.rangeFromRegExp(token.line, htmlRe));
|
||||
rangeFromRegExp(token.line, htmlRe));
|
||||
}
|
||||
});
|
||||
}
|
||||
shared.filterTokens(params, "html_block", forToken);
|
||||
shared.forEachInlineChild(params, "html_inline", forToken);
|
||||
filterTokens(params, "html_block", forToken);
|
||||
forEachInlineChild(params, "html_inline", forToken);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue