File tree Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -101,19 +101,31 @@ export const renderText = (text, mentioned_users) => {
101101 let newText = text ;
102102 let markdownLinks = matchMarkdownLinks ( newText ) ;
103103 let codeBlocks = messageCodeBlocks ( newText ) ;
104+ const detectHttp = / ( h t t p ( s ? ) : \/ \/ ) ? ( w w w \. ) ? / ;
105+
104106 // extract all valid links/emails within text and replace it with proper markup
105107 linkify . find ( newText ) . forEach ( ( { type, href, value } ) => {
106108 const linkIsInBlock = codeBlocks . some ( ( block ) => block ?. includes ( value ) ) ;
109+
107110 // check if message is already markdown
108111 const noParsingNeeded =
109112 markdownLinks &&
110- markdownLinks . filter ( ( text ) => text ?. indexOf ( href ) !== - 1 ) ;
113+ markdownLinks . filter ( ( text ) => {
114+ const strippedHref = href ?. replace ( detectHttp , '' ) ;
115+ const strippedText = text ?. replace ( detectHttp , '' ) ;
116+
117+ if ( ! strippedHref || ! strippedText ) return false ;
118+
119+ return (
120+ strippedHref . includes ( strippedText ) ||
121+ strippedText . includes ( strippedHref )
122+ ) ;
123+ } ) ;
124+
111125 if ( noParsingNeeded . length > 0 || linkIsInBlock ) return ;
112126
113127 const displayLink =
114- type === 'email'
115- ? value
116- : truncate ( value . replace ( / ( h t t p ( s ? ) : \/ \/ ) ? ( w w w \. ) ? / , '' ) , 20 ) ;
128+ type === 'email' ? value : truncate ( value . replace ( detectHttp , '' ) , 20 ) ;
117129 newText = newText . replace ( value , `[${ displayLink } ](${ encodeURI ( href ) } )` ) ;
118130 } ) ;
119131
You can’t perform that action at this time.
0 commit comments