diff --git a/lib/md033.js b/lib/md033.js index 87366f23b..a50614c30 100644 --- a/lib/md033.js +++ b/lib/md033.js @@ -6,8 +6,12 @@ const { addError, bareUrlRe, forEachLine, unescapeMarkdown } = require("../helpers"); const { lineMetadata } = require("./cache"); -const htmlElementRe = /<(\w+)(?:[^>]*)?>/g; +const htmlElementRe = /<(([\w+.-]+)(?:[^>]*)?)>/g; const linkDestinationRe = /]\(\s*$/; +// See https://spec.commonmark.org/0.29/#autolinks +const emailAddressRe = + // eslint-disable-next-line max-len + /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/; module.exports = { "names": [ "MD033", "no-inline-html" ], @@ -20,9 +24,10 @@ module.exports = { let match = null; // eslint-disable-next-line no-unmodified-loop-condition while (!inCode && (match = htmlElementRe.exec(line))) { - const [ tag, element ] = match; + const [ tag, content, element ] = match; if (!allowedElements.includes(element.toLowerCase()) && - !tag.endsWith("\\>") && !bareUrlRe.test(tag)) { + !tag.endsWith("\\>") && !bareUrlRe.test(content) && + !emailAddressRe.test(content)) { const prefix = line.substring(0, match.index); if (!linkDestinationRe.test(prefix) && !unescapeMarkdown(prefix + "<", "_").endsWith("_")) { diff --git a/test/detailed-results-html-tags.md b/test/detailed-results-html-tags.md index 7579484a3..a3ffcdab0 100644 --- a/test/detailed-results-html-tags.md +++ b/test/detailed-results-html-tags.md @@ -79,3 +79,13 @@ Text inline text text text Text + + is an email autolink. + +Text + +Another email autolink: . + +Text + +But is not an email autolink. diff --git a/test/detailed-results-html-tags.results.json b/test/detailed-results-html-tags.results.json index a35a31ed7..2968521fc 100644 --- a/test/detailed-results-html-tags.results.json +++ b/test/detailed-results-html-tags.results.json @@ -151,5 +151,14 @@ "errorDetail": "Element: img", "errorContext": null, "errorRange": [ 6, 20 ] + }, + { + "lineNumber": 91, + "ruleNames": [ "MD033", "no-inline-html" ], + "ruleDescription": "Inline HTML", + "ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md033", + "errorDetail": "Element: foo.bar.baz", + "errorContext": null, + "errorRange": [ 5, 13 ] } ]