mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Update MD033/no-inline-html to ignore email autolinks (fixes #183).
This commit is contained in:
parent
ad8e4007c0
commit
f003926a72
3 changed files with 27 additions and 3 deletions
11
lib/md033.js
11
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("_")) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue