add mailto protocol support for external links
This commit is contained in:
parent
155672ee7b
commit
1edf7e06f9
3 changed files with 15 additions and 4 deletions
|
@ -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 && (
|
||||
<Fragment>
|
||||
<div className="media__info-title">{__('Contact')}</div>
|
||||
<div className="media__info-text">{email}</div>
|
||||
<div className="media__info-text">
|
||||
<MarkdownPreview content={formatEmail(email)} promptLinks />
|
||||
</div>
|
||||
</Fragment>
|
||||
)}
|
||||
{website && (
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -22,14 +22,14 @@ class ExternalLink extends React.PureComponent<Props> {
|
|||
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 = <span>{children}</span>;
|
||||
|
||||
// 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 = (
|
||||
<Button
|
||||
button="link"
|
||||
|
|
Loading…
Add table
Reference in a new issue