feature(MD033): adding tagName filter option to config for "Inline HTML"

This commit is contained in:
Rodney Rehm 2015-07-21 17:19:25 +02:00
parent eabe2387bc
commit aa733719b0
2 changed files with 27 additions and 7 deletions

View file

@ -118,7 +118,7 @@ function lintContent(content, config) {
// Configure rule
params.options = mergedRules[rule.name];
var errors = [];
rule.func(params, errors);
rule.func(params, errors, config);
// Record any errors
if (errors.length) {
errors.sort(numberComparison);

View file

@ -627,13 +627,33 @@ module.exports = [
"name": "MD033",
"desc": "Inline HTML",
"tags": [ "html" ],
"func": function MD033(params, errors) {
filterTokens(params, "html_block", function forToken(token) {
errors.push(token.lineNumber);
});
forEachInlineChild(params, "html_inline", function forToken(token) {
errors.push(token.lineNumber);
"func": function MD033(params, errors, config) {
// map allowed tags
var allowed = {};
(config.MD033 || []).forEach(function mapTagName(tagName) {
allowed[tagName.toLowerCase()] = true;
});
// expression to extract tag names
// (closing tags are coming in from the tokens as well)
var tagNamePattern = /<\/?([^ >]+)/ig;
function forToken(token) {
// abusing replace because we then don't
// have to deal with the .lastIndex mess
/*eslint-disable max-len */
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec#Finding_successive_matches
/*eslint-enable max-len */
var badHtml = false;
token.content.replace(tagNamePattern, function forTagName(m, tagName) {
badHtml = badHtml || !allowed[tagName.toLowerCase()];
return m;
});
if (badHtml) {
errors.push(token.lineNumber);
}
}
filterTokens(params, "html_block", forToken);
forEachInlineChild(params, "html_inline", forToken);
}
},