mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 22:40:13 +01:00
Move each rule implementation into its own file (fixes #83).
This commit is contained in:
parent
49e36f817c
commit
9ba143555d
42 changed files with 1289 additions and 1028 deletions
41
lib/md033.js
Normal file
41
lib/md033.js
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
// @ts-check
|
||||
|
||||
"use strict";
|
||||
|
||||
var shared = require("./shared");
|
||||
|
||||
var htmlRe = /<[^>]*>/;
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD033", "no-inline-html" ],
|
||||
"description": "Inline HTML",
|
||||
"tags": [ "html" ],
|
||||
"function": function MD033(params, onError) {
|
||||
var allowedElements = (params.config.allowed_elements || [])
|
||||
.map(function forElement(element) {
|
||||
return element.toLowerCase();
|
||||
});
|
||||
function forToken(token) {
|
||||
token.content.split(shared.newLineRe)
|
||||
.forEach(function forLine(line, offset) {
|
||||
var 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;
|
||||
});
|
||||
if (allowed.length) {
|
||||
shared.addError(onError, token.lineNumber + offset,
|
||||
"Element: " + allowed[0], null,
|
||||
shared.rangeFromRegExp(token.line, htmlRe));
|
||||
}
|
||||
});
|
||||
}
|
||||
shared.filterTokens(params, "html_block", forToken);
|
||||
shared.forEachInlineChild(params, "html_inline", forToken);
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue