11// @flow
22import React from 'react' ;
3+ import { Link } from 'react-router-dom' ;
34import Highlight , { defaultProps } from 'prism-react-renderer' ;
45import { Line , Paragraph , BlockQuote } from 'src/components/message/style' ;
56import {
@@ -13,6 +14,7 @@ import { hasStringElements } from '../utils/hasStringElements';
1314import mentionsDecorator from '../mentions-decorator' ;
1415import linksDecorator from '../links-decorator' ;
1516import type { Node } from 'react' ;
17+ import { SPECTRUM_URLS } from 'shared/regexps' ;
1618import type { KeyObj , KeysObj , DataObj } from '../message/types' ;
1719import type {
1820 EmbedData ,
@@ -159,16 +161,23 @@ export const createRenderer = (options: Options) => {
159161 ) ,
160162 } ,
161163 entities : {
162- LINK : ( children : Array < Node > , data : DataObj , { key } : KeyObj ) => (
163- < a
164- key = { key }
165- href = { data . url || data . href }
166- target = "_blank"
167- rel = "noopener noreferrer"
168- >
169- { children }
170- </ a >
171- ) ,
164+ LINK : ( children : Array < Node > , data : DataObj , { key } : KeyObj ) => {
165+ const link = data . url || data . href ;
166+
167+ if ( typeof link !== 'string' ) {
168+ return (
169+ < a key = { key } href = { link } target = "_blank" rel = "noopener noreferrer" >
170+ { children }
171+ </ a >
172+ ) ;
173+ }
174+
175+ const regexp = new RegExp ( SPECTRUM_URLS , 'ig' ) ;
176+ const match = regexp . exec ( link ) ;
177+ if ( match && match [ 0 ] && match [ 1 ] ) {
178+ return < Link to = { match [ 1 ] } > { children } </ Link > ;
179+ }
180+ } ,
172181 IMAGE : (
173182 children : Array < Node > ,
174183 data : { src ? : string , alt ?: string } ,
0 commit comments