This commit is contained in:
Rodney Rehm 2015-09-25 05:11:42 +00:00
commit 1c2241fc62
2 changed files with 27 additions and 7 deletions

View file

@ -133,7 +133,7 @@ function lintContent(content, config, frontMatter) {
// 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

@ -639,13 +639,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);
}
},