Skip to content

Commit

Permalink
Update MD033/no-inline-html to ignore email autolinks (fixes #183).
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidAnson committed May 9, 2019
1 parent ad8e400 commit f003926
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/md033.js
Expand Up @@ -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" ],
Expand All @@ -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("_")) {
Expand Down
10 changes: 10 additions & 0 deletions test/detailed-results-html-tags.md
Expand Up @@ -79,3 +79,13 @@ Text <a href="#anchor">inline</a> text
text <img src="src.png"/> text

Text

<name@example.com> is an email autolink.

Text

Another email autolink: <first+last@ex.exa-mple.com>.

Text

But <foo.bar.baz> is not an email autolink.
9 changes: 9 additions & 0 deletions test/detailed-results-html-tags.results.json
Expand Up @@ -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 ]
}
]

0 comments on commit f003926

Please sign in to comment.