diff --git a/lib/markdownlint.js b/lib/markdownlint.js index ae7a6f56..6b31a674 100644 --- a/lib/markdownlint.js +++ b/lib/markdownlint.js @@ -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); diff --git a/lib/rules.js b/lib/rules.js index 14ee4c87..3f961751 100644 --- a/lib/rules.js +++ b/lib/rules.js @@ -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); } },