diff --git a/web/src/app/chat/message/CodeBlock.tsx b/web/src/app/chat/message/CodeBlock.tsx index 8c6d984a4c..297ccf4933 100644 --- a/web/src/app/chat/message/CodeBlock.tsx +++ b/web/src/app/chat/message/CodeBlock.tsx @@ -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; diff --git a/web/src/app/chat/message/Messages.tsx b/web/src/app/chat/message/Messages.tsx index 47623f7e5c..8a2d461c4a 100644 --- a/web/src/app/chat/message/Messages.tsx +++ b/web/src/app/chat/message/Messages.tsx @@ -236,7 +236,7 @@ export const AIMessage = ({ ), }} remarkPlugins={[remarkGfm]} - rehypePlugins={[rehypePrism]} + rehypePlugins={[[rehypePrism, { ignoreMissing: true }]]} > {content}