mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-07-03 11:11:45 +02:00
Fix unknown languages causing the chat to crash
This commit is contained in:
@ -51,6 +51,27 @@ export function CodeBlock({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handle unknown languages. They won't have a `node.position.start.offset`
|
||||||
|
if (!codeText) {
|
||||||
|
const findTextNode = (node: any): string | null => {
|
||||||
|
if (node.type === "text") {
|
||||||
|
return node.value;
|
||||||
|
}
|
||||||
|
let finalResult = "";
|
||||||
|
if (node.children) {
|
||||||
|
for (const child of node.children) {
|
||||||
|
const result = findTextNode(child);
|
||||||
|
if (result) {
|
||||||
|
finalResult += result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return finalResult;
|
||||||
|
};
|
||||||
|
|
||||||
|
codeText = findTextNode(props.node);
|
||||||
|
}
|
||||||
|
|
||||||
const handleCopy = () => {
|
const handleCopy = () => {
|
||||||
if (!codeText) {
|
if (!codeText) {
|
||||||
return;
|
return;
|
||||||
|
@ -236,7 +236,7 @@ export const AIMessage = ({
|
|||||||
),
|
),
|
||||||
}}
|
}}
|
||||||
remarkPlugins={[remarkGfm]}
|
remarkPlugins={[remarkGfm]}
|
||||||
rehypePlugins={[rehypePrism]}
|
rehypePlugins={[[rehypePrism, { ignoreMissing: true }]]}
|
||||||
>
|
>
|
||||||
{content}
|
{content}
|
||||||
</ReactMarkdown>
|
</ReactMarkdown>
|
||||||
|
Reference in New Issue
Block a user