File tree 4 files changed +701
-35
lines changed
4 files changed +701
-35
lines changed Original file line number Diff line number Diff line change 27
27
"microsoft-cognitiveservices-speech-sdk" : " ^1.31.0" ,
28
28
"react" : " ^18.2.0" ,
29
29
"react-dom" : " ^18.2.0" ,
30
- "react-redux" : " ^8.1.2"
30
+ "react-markdown" : " ^8.0.7" ,
31
+ "react-redux" : " ^8.1.2" ,
32
+ "remark-gfm" : " ^3.0.1"
31
33
},
32
34
"devDependencies" : {
33
35
"@babel/plugin-proposal-private-property-in-object" : " ^7.21.11" ,
Original file line number Diff line number Diff line change 2
2
3
3
import { makeStyles } from '@fluentui/react-components' ;
4
4
import React from 'react' ;
5
+ import ReactMarkdown from 'react-markdown' ;
6
+ import remarkGfm from 'remark-gfm' ;
5
7
import { IChatMessage } from '../../../libs/models/ChatMessage' ;
6
- import { convertToAnchorTags } from '../../utils/TextUtils' ;
7
8
import * as utils from './../../utils/TextUtils' ;
8
9
9
10
const useClasses = makeStyles ( {
@@ -18,12 +19,11 @@ interface ChatHistoryTextContentProps {
18
19
19
20
export const ChatHistoryTextContent : React . FC < ChatHistoryTextContentProps > = ( { message } ) => {
20
21
const classes = useClasses ( ) ;
22
+ const content = utils . formatChatTextContent ( message . content ) ;
21
23
22
- let content = message . content . trim ( ) . replace ( / [ \u00A0 - \u9999 < > & ] / g, function ( i : string ) {
23
- return `&#${ i . charCodeAt ( 0 ) } ;` ;
24
- } ) ;
25
- content = utils . formatChatTextContent ( content ) ;
26
- content = content . replace ( / \n / g, '<br />' ) . replace ( / { 2 } / g, ' ' ) ;
27
-
28
- return < div className = { classes . content } dangerouslySetInnerHTML = { { __html : convertToAnchorTags ( content ) } } /> ;
24
+ return (
25
+ < div className = { classes . content } >
26
+ < ReactMarkdown remarkPlugins = { [ remarkGfm ] } > { content } </ ReactMarkdown >
27
+ </ div >
28
+ ) ;
29
29
} ;
Original file line number Diff line number Diff line change 1
1
import { Body1 , tokens } from '@fluentui/react-components' ;
2
2
3
- /*
4
- * Function to detect and convert URLs within a string into clickable links.
5
- * It wraps each link matched with anchor tags and applies safe href attributes.
6
- */
7
- export function convertToAnchorTags ( htmlString : string ) {
8
- // Regular expression to match links, excluding any HTML tags at the end
9
- // Since response from bot is plain text, sometimes line breaks and other html tags are included in the response for readability.
10
- const linkRegex =
11
- / (?: h t t p s ? ) : \/ \/ ( \w + : ? \w * ) ? ( \S + ) ( : \d + ) ? ( \/ | \/ ( [ \w # ! : . ? + = & % ! \- / ] ) ) ? (? = ( < b r | < p | < d i v | < s p a n ) \s * \/ > | $ ) / g;
12
-
13
- const result = htmlString . replace ( linkRegex , function ( link ) {
14
- // Parse URL first -- URL class handles cybersecurity concerns related to URL parsing and manipulation
15
- const safeHref = new URL ( link ) . toString ( ) ;
16
-
17
- // Replace each link with anchor tags
18
- return `<a href="${ safeHref } ">${ link } </a>` ;
19
- } ) ;
20
-
21
- return result ;
22
- }
23
-
24
3
/*
25
4
* Function to check if date is today.
26
5
*/
You can’t perform that action at this time.
0 commit comments