Skip to content

Commit a7be154

Browse files
Merge pull request microsoft#175 from microsoft/dependabotchanges-2
fix : updated code and update package.json file
2 parents 958dcf8 + c5f6277 commit a7be154

File tree

3 files changed

+43
-17
lines changed

3 files changed

+43
-17
lines changed

frontend/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"react-syntax-highlighter": "^15.6.1",
3434
"react-uuid": "^2.0.0",
3535
"rehype-raw": "^7.0.0",
36-
"remark-gfm": "^3.0.1",
36+
"remark-gfm": "^4.0.0",
3737
"remark-supersub": "^1.0.0"
3838
},
3939
"devDependencies": {
@@ -50,8 +50,8 @@
5050
"@types/react-dom": "^18.0.10",
5151
"@types/react-plotly.js": "^2.6.3",
5252
"@types/react-syntax-highlighter": "^15.5.13",
53-
"@typescript-eslint/eslint-plugin": "^8.18.2",
54-
"@typescript-eslint/parser": "^8.18.2",
53+
"@typescript-eslint/eslint-plugin": "^6.4.0",
54+
"@typescript-eslint/parser": "^6.4.0",
5555
"@vitejs/plugin-react": "^4.3.4",
5656
"eslint": "^8.57.0",
5757
"eslint-config-prettier": "^9.1.0",

frontend/src/components/Answer/Answer.tsx

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { FormEvent, useContext, useEffect, useMemo, useState } from 'react'
22
import ReactMarkdown from 'react-markdown'
3+
import { Components } from 'react-markdown';
34
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'
45
import { nord } from 'react-syntax-highlighter/dist/esm/styles/prism'
56
import { Checkbox, DefaultButton, Dialog, FontIcon, Stack, Text } from '@fluentui/react'
@@ -225,19 +226,38 @@ export const Answer = ({ answer, onCitationClicked }: Props) => {
225226
)
226227
}
227228

228-
const components = {
229-
code({ node, ...props }: { node: any; [key: string]: any }) {
230-
let language
231-
if (props.className) {
232-
const match = props.className.match(/language-(\w+)/)
233-
language = match ? match[1] : undefined
229+
const components: Components = {
230+
a: ({ href, children, ...props }) => (
231+
<a href={href} target="_blank" rel="noopener noreferrer" {...props}>
232+
{children}
233+
</a>
234+
),
235+
code({ inline, className, children, ...props }: {
236+
inline?: boolean;
237+
className?: string;
238+
children?: React.ReactNode;
239+
[key: string]: any
240+
}) {
241+
const match = /language-(\w+)/.exec(className || '');
242+
// Handle inline and block code rendering
243+
if (inline) {
244+
return (
245+
<code className={className} {...props}>
246+
{children}
247+
</code>
248+
);
249+
} else if (match) {
250+
return (
251+
<SyntaxHighlighter
252+
style={nord}
253+
language={match[1]}
254+
PreTag="div"
255+
{...props}
256+
>
257+
{String(children).replace(/\n$/, '')}
258+
</SyntaxHighlighter>
259+
);
234260
}
235-
const codeString = node.children[0].value ?? ''
236-
return (
237-
<SyntaxHighlighter style={nord} language={language} PreTag="div" {...props}>
238-
{codeString}
239-
</SyntaxHighlighter>
240-
)
241261
}
242262
}
243263
return (
@@ -247,7 +267,6 @@ export const Answer = ({ answer, onCitationClicked }: Props) => {
247267
<Stack horizontal grow>
248268
<Stack.Item grow>
249269
<ReactMarkdown
250-
linkTarget="_blank"
251270
remarkPlugins={[remarkGfm, supersub]}
252271
children={
253272
SANITIZE_ANSWER

frontend/src/pages/chat/Chat.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ interface Props {
105105
type?: ChatType
106106
}
107107

108+
109+
const renderLink = (props: any) => {
110+
return <a {...props} target="_blank" rel="noopener noreferrer" />;
111+
};
112+
108113
const Chat = ({ type = ChatType.Browse }: Props) => {
109114
const location = useLocation()
110115

@@ -1126,11 +1131,13 @@ const Chat = ({ type = ChatType.Browse }: Props) => {
11261131
</h5>
11271132
<div tabIndex={0}>
11281133
<ReactMarkdown
1129-
linkTarget="_blank"
11301134
className={styles.citationPanelContent}
11311135
children={DOMPurify.sanitize(activeCitation.content, { ALLOWED_TAGS: XSSAllowTags })}
11321136
remarkPlugins={[remarkGfm]}
11331137
rehypePlugins={[rehypeRaw]}
1138+
components={{
1139+
a: renderLink,
1140+
}}
11341141
/>
11351142
</div>
11361143
</Stack.Item>

0 commit comments

Comments
 (0)