Skip to content

Commit 34e6c27

Browse files
Merge pull request #240 from microsoft/dependabotchanges-1
fix: updated package.json and update code in answer.tsx and citationPane
2 parents e08b1cf + 9d3f06e commit 34e6c27

File tree

8 files changed

+3957
-20794
lines changed

8 files changed

+3957
-20794
lines changed

ClientAdvisor/App/frontend/package-lock.json

Lines changed: 3417 additions & 19885 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ClientAdvisor/App/frontend/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"react-syntax-highlighter": "^15.6.1",
3030
"react-uuid": "^2.0.0",
3131
"rehype-raw": "^7.0.0",
32-
"remark-gfm": "^3.0.1",
32+
"remark-gfm": "^4.0.0",
3333
"remark-supersub": "^1.0.0",
3434
"undici": "^7.2.0"
3535
},
@@ -49,15 +49,15 @@
4949
"@types/react-dom": "^18.0.10",
5050
"@types/react-syntax-highlighter": "^15.5.13",
5151
"@types/testing-library__user-event": "^4.2.0",
52-
"@typescript-eslint/eslint-plugin": "^8.18.1",
53-
"@typescript-eslint/parser": "^8.18.1",
52+
"@typescript-eslint/eslint-plugin": "^6.4.0",
53+
"@typescript-eslint/parser": "^6.4.0",
5454
"@vitejs/plugin-react": "^4.3.4",
5555
"dotenv": "^16.4.5",
5656
"eslint": "^8.57.0",
5757
"eslint-config-prettier": "^9.1.0",
5858
"eslint-config-standard-with-typescript": "^43.0.1",
5959
"eslint-plugin-jsx-a11y": "^6.10.2",
60-
"eslint-plugin-n": "^17.15.1",
60+
"eslint-plugin-n": "^16.0.0",
6161
"eslint-plugin-prettier": "^5.2.1",
6262
"eslint-plugin-promise": "^6.6.0",
6363
"eslint-plugin-react": "^7.37.2",

ClientAdvisor/App/frontend/src/components/Answer/Answer.tsx

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { FormEvent, useContext, useEffect, useMemo, useState } from 'react'
2-
import ReactMarkdown from 'react-markdown'
2+
import ReactMarkdown, { Components, Options } from 'react-markdown'
33
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'
44
import { nord } from 'react-syntax-highlighter/dist/esm/styles/prism'
55
import { Checkbox, DefaultButton, Dialog, FontIcon, Stack, Text } from '@fluentui/react'
@@ -228,19 +228,38 @@ export const Answer = ({ answer, onCitationClicked }: Props) => {
228228
)
229229
}
230230

231-
const components = {
232-
code({ node, ...props }: { node: any;[key: string]: any }) {
233-
let language
234-
if (props.className) {
235-
const match = props.className.match(/language-(\w+)/)
236-
language = match ? match[1] : undefined
231+
const components: Components = {
232+
a: ({ href, children, ...props }) => (
233+
<a href={href} target="_blank" rel="noopener noreferrer" {...props}>
234+
{children}
235+
</a>
236+
),
237+
code({ inline, className, children, ...props }: {
238+
inline?: boolean;
239+
className?: string;
240+
children?: React.ReactNode;
241+
[key: string]: any
242+
}) {
243+
const match = /language-(\w+)/.exec(className || '');
244+
// Handle inline and block code rendering
245+
if (inline) {
246+
return (
247+
<code className={className} {...props}>
248+
{children}
249+
</code>
250+
);
251+
} else if (match) {
252+
return (
253+
<SyntaxHighlighter
254+
style={nord}
255+
language={match[1]}
256+
PreTag="div"
257+
{...props}
258+
>
259+
{String(children).replace(/\n$/, '')}
260+
</SyntaxHighlighter>
261+
);
237262
}
238-
const codeString = node.children[0].value ?? ''
239-
return (
240-
<SyntaxHighlighter style={nord} language={language} PreTag="div" {...props}>
241-
{codeString}
242-
</SyntaxHighlighter>
243-
)
244263
}
245264
}
246265
return (
@@ -249,18 +268,17 @@ export const Answer = ({ answer, onCitationClicked }: Props) => {
249268
<Stack.Item>
250269
<Stack horizontal grow>
251270
<Stack.Item grow>
252-
<ReactMarkdown
253-
linkTarget="_blank"
254-
remarkPlugins={[remarkGfm, supersub]}
255-
rehypePlugins={[rehypeRaw]}
256-
children={
257-
SANITIZE_ANSWER
258-
? DOMPurify.sanitize(parsedAnswer.markdownFormatText, { ALLOWED_TAGS: XSSAllowTags })
259-
: parsedAnswer.markdownFormatText
260-
}
261-
className={styles.answerText}
262-
components={components}
263-
/>
271+
<ReactMarkdown
272+
remarkPlugins={[remarkGfm, supersub]}
273+
rehypePlugins={[rehypeRaw]}
274+
children={
275+
SANITIZE_ANSWER
276+
? DOMPurify.sanitize(parsedAnswer.markdownFormatText, { ALLOWED_TAGS: XSSAllowTags, ALLOWED_ATTR: ['href', 'target', 'rel'] })
277+
: parsedAnswer.markdownFormatText
278+
}
279+
className={styles.answerText}
280+
components={components}
281+
/>
264282
</Stack.Item>
265283
<Stack.Item className={styles.answerHeader}>
266284
{FEEDBACK_ENABLED && answer.message_id !== undefined && (

ClientAdvisor/App/frontend/src/pages/chat/Components/CitationPanel.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ interface CitationPanelProps {
1515
}
1616

1717
export const CitationPanel: React.FC<CitationPanelProps> = ({ activeCitation, IsCitationPanelOpen, onViewSource }) => {
18+
19+
const renderLink = (props: any) => {
20+
return <a {...props} target="_blank" rel="noopener noreferrer" />;
21+
};
1822
return (
1923
<Stack.Item className={styles.citationPanel} tabIndex={0} role="tabpanel" aria-label="Citations Panel">
2024
<Stack
@@ -41,11 +45,13 @@ export const CitationPanel: React.FC<CitationPanelProps> = ({ activeCitation, Is
4145
</h5>
4246
<div tabIndex={0}>
4347
<ReactMarkdown
44-
linkTarget="_blank"
4548
className={styles.citationPanelContent}
4649
children={DOMPurify.sanitize(activeCitation.content, { ALLOWED_TAGS: XSSAllowTags })}
4750
remarkPlugins={[remarkGfm]}
4851
rehypePlugins={[rehypeRaw]}
52+
components={{
53+
a: renderLink,
54+
}}
4955
/>
5056
</div>
5157
</Stack.Item>

0 commit comments

Comments
 (0)