From 1edf7e06f91265e85eb2679c223b012dec46f7b5 Mon Sep 17 00:00:00 2001 From: btzr-io Date: Wed, 29 May 2019 17:21:20 -0600 Subject: [PATCH] add mailto protocol support for external links --- src/ui/component/channelAbout/view.jsx | 13 ++++++++++++- .../component/common/markdown-preview-internal.jsx | 2 +- src/ui/component/externalLink/view.jsx | 4 ++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/ui/component/channelAbout/view.jsx b/src/ui/component/channelAbout/view.jsx index 9d7982b54..2bde04b87 100644 --- a/src/ui/component/channelAbout/view.jsx +++ b/src/ui/component/channelAbout/view.jsx @@ -8,6 +8,15 @@ type Props = { website: ?string, }; +const formatEmail = (email: string) => { + if (email) { + const protocolRegex = new RegExp('^mailto:', 'i'); + const protocol = protocolRegex.exec(email); + return protocol ? email : `mailto:${email}`; + } + return null; +}; + function ChannelContent(props: Props) { const { description, email, website } = props; const showAbout = description || email || website; @@ -25,7 +34,9 @@ function ChannelContent(props: Props) { {email && (
{__('Contact')}
-
{email}
+
+ +
)} {website && ( diff --git a/src/ui/component/common/markdown-preview-internal.jsx b/src/ui/component/common/markdown-preview-internal.jsx index 78af2273d..8acf727bb 100644 --- a/src/ui/component/common/markdown-preview-internal.jsx +++ b/src/ui/component/common/markdown-preview-internal.jsx @@ -30,7 +30,7 @@ const SimpleLink = (props: SimpleLinkProps) => { const schema = { ...defaultSchema }; // Extend sanitation schema to support lbry protocol -schema.protocols.href[3] = 'lbry'; +schema.protocols.href.push('lbry'); const MarkdownPreview = (props: MarkdownProps) => { const { content, promptLinks } = props; diff --git a/src/ui/component/externalLink/view.jsx b/src/ui/component/externalLink/view.jsx index ccab6ad27..36607e9ad 100644 --- a/src/ui/component/externalLink/view.jsx +++ b/src/ui/component/externalLink/view.jsx @@ -22,14 +22,14 @@ class ExternalLink extends React.PureComponent { const { href, title, children, openModal } = this.props; // Regex for url protocol - const protocolRegex = new RegExp('^(https?|lbry)+:', 'i'); + const protocolRegex = new RegExp('^(https?|lbry|mailto)+:', 'i'); const protocol = href ? protocolRegex.exec(href) : null; // Return plain text if no valid url let element = {children}; // Return external link if protocol is http or https - if (protocol && (protocol[0] === 'http:' || protocol[0] === 'https:')) { + if (protocol && (protocol[0] === 'http:' || protocol[0] === 'https:' || protocol[0] === 'mailto:')) { element = (