From eb64073890554e9e13381f34c5bdecefe00048ec Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Fri, 24 Sep 2021 06:42:37 +0000 Subject: [PATCH] Fix for email domains with no letters GitHub does not link strings of the format mdast-util-gfm-autolink-literal@1.0.1 but will link if you add a letter to the label/domain. Emulate that behavior. Ref: https://github.com/remarkjs/remark/discussions/862 --- index.js | 5 +++++ test/base.html | 1 + test/base.md | 2 ++ 3 files changed, 8 insertions(+) diff --git a/index.js b/index.js index 281e6c6..d927ceb 100644 --- a/index.js +++ b/index.js @@ -158,6 +158,11 @@ function findEmail(_, atext, label, match) { return false } + // Do not link if label does not contain a letter. + if (!/[a-z]/i.test(label)) { + return false + } + return { type: 'link', title: null, diff --git a/test/base.html b/test/base.html index 0fab254..b180827 100644 --- a/test/base.html +++ b/test/base.html @@ -53,6 +53,7 @@

Email autolinks

a@a-b.c

Can’t end in an underscore followed by a period: aaa@a.b_.

Can contain an underscore followed by a period: aaa@a.b_.c

+

Can't have a domain with no letters: mdast-util-gfm-autolink-literal@1.0.1

Link text should not be expanded

Visit www.example.com please.

Visit http://www.example.com please.

diff --git a/test/base.md b/test/base.md index 84ba70e..4154927 100644 --- a/test/base.md +++ b/test/base.md @@ -108,6 +108,8 @@ Can’t end in an underscore followed by a period: aaa@a.b_. Can contain an underscore followed by a period: aaa@a.b_.c +Can't have a domain with no letters: mdast-util-gfm-autolink-literal@1.0.1 + ## Link text should not be expanded [Visit www.example.com](http://www.example.com) please.