From e9a68c179947c899398af400ea9f115d6714f5fe Mon Sep 17 00:00:00 2001 From: Diego Islas Ocampo Date: Tue, 30 Mar 2021 19:31:43 -0600 Subject: [PATCH] Add email address protocol for link inline tool --- src/components/inline-tools/inline-tool-link.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/components/inline-tools/inline-tool-link.ts b/src/components/inline-tools/inline-tool-link.ts index b55120bb..3cc98754 100644 --- a/src/components/inline-tools/inline-tool-link.ts +++ b/src/components/inline-tools/inline-tool-link.ts @@ -368,13 +368,18 @@ export default class LinkInlineTool implements InlineTool { * 1) Internal links like "/general" * 2) Anchors looks like "#results" * 3) Protocol-relative URLs like "//google.com" + * 4) Email addresses like "example@example.com" */ const isInternal = /^\/[^/\s]/.test(link), isAnchor = link.substring(0, 1) === '#', - isProtocolRelative = /^\/\/[^/\s]/.test(link); + isProtocolRelative = /^\/\/[^/\s]/.test(link), + // eslint-disable-next-line no-useless-escape + isEmail = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(link); if (!isInternal && !isAnchor && !isProtocolRelative) { - link = 'http://' + link; + const protocol = isEmail ? 'mailto:' : 'http://'; + + link = protocol + link; } return link;