@@ -295,18 +295,24 @@ export class MessageComponent implements OnInit, OnChanges, OnDestroy {
295295 if ( ! content ) {
296296 this . messageTextParts = [ ] ;
297297 } else {
298+ let isHTML = false ;
298299 // Backend will wrap HTML content with <p></p>\n
299300 if ( content . startsWith ( '<p>' ) ) {
300301 content = content . replace ( '<p>' , '' ) ;
302+ isHTML = true ;
301303 }
302304 if ( content . endsWith ( '</p>\n' ) ) {
303305 content = content . replace ( '</p>\n' , '' ) ;
306+ isHTML = true ;
304307 }
305308 if (
306309 ! this . message ! . mentioned_users ||
307310 this . message ! . mentioned_users . length === 0
308311 ) {
309312 content = this . fixEmojiDisplay ( content ) ;
313+ if ( ! isHTML ) {
314+ content = this . wrapLinskWithAnchorTag ( content ) ;
315+ }
310316 this . messageTextParts = [ { content, type : 'text' } ] ;
311317 } else {
312318 this . messageTextParts = [ ] ;
@@ -315,6 +321,9 @@ export class MessageComponent implements OnInit, OnChanges, OnDestroy {
315321 const mention = `@${ user . name || user . id } ` ;
316322 let precedingText = text . substring ( 0 , text . indexOf ( mention ) ) ;
317323 precedingText = this . fixEmojiDisplay ( precedingText ) ;
324+ if ( ! isHTML ) {
325+ precedingText = this . wrapLinskWithAnchorTag ( precedingText ) ;
326+ }
318327 this . messageTextParts . push ( {
319328 content : precedingText ,
320329 type : 'text' ,
@@ -328,6 +337,9 @@ export class MessageComponent implements OnInit, OnChanges, OnDestroy {
328337 } ) ;
329338 if ( text ) {
330339 text = this . fixEmojiDisplay ( text ) ;
340+ if ( ! isHTML ) {
341+ text = this . wrapLinskWithAnchorTag ( text ) ;
342+ }
331343 this . messageTextParts . push ( { content : text , type : 'text' } ) ;
332344 }
333345 }
@@ -352,4 +364,15 @@ export class MessageComponent implements OnInit, OnChanges, OnDestroy {
352364
353365 return content ;
354366 }
367+
368+ private wrapLinskWithAnchorTag ( content : string ) {
369+ const urlRegexp =
370+ / (?: (?: h t t p s ? | f t p | f i l e ) : \/ \/ | w w w \. | f t p \. ) (?: \( [ - A - Z 0 - 9 + & @ # / % = ~ _ | $ ? ! : , . ] * \) | [ - A - Z 0 - 9 + & @ # / % = ~ _ | $ ? ! : , . ] ) * (?: \( [ - A - Z 0 - 9 + & @ # / % = ~ _ | $ ? ! : , . ] * \) | [ A - Z 0 - 9 + & @ # / % = ~ _ | $ ] ) / gim;
371+ content = content . replace (
372+ urlRegexp ,
373+ ( match ) => `<a href="${ match } " rel="nofollow">${ match } </a>`
374+ ) ;
375+
376+ return content ;
377+ }
355378}
0 commit comments