Fix unknown languages causing the chat to crash

This commit is contained in:
Weves
2024-05-27 14:09:32 -07:00
committed by Chris Weaver
parent 90d5b41901
commit 9a3613eb44
2 changed files with 22 additions and 1 deletions

View File

@ -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 = () => {
if (!codeText) {
return;

View File

@ -236,7 +236,7 @@ export const AIMessage = ({
),
}}
remarkPlugins={[remarkGfm]}
rehypePlugins={[rehypePrism]}
rehypePlugins={[[rehypePrism, { ignoreMissing: true }]]}
>
{content}
</ReactMarkdown>