add copying for unrecognized languages (#2883)

* add copying for unrecognized languages

* k
This commit is contained in:
pablodanswer 2024-10-23 10:26:54 -07:00 committed by GitHub
parent 5703ea47d2
commit 143da5bc0d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 24 additions and 2 deletions

View File

@ -348,7 +348,6 @@ export function getCitedDocumentsFromMessage(message: Message) {
}
export function groupSessionsByDateRange(chatSessions: ChatSession[]) {
console.log(chatSessions);
const today = new Date();
today.setHours(0, 0, 0, 0); // Set to start of today for accurate comparison

View File

@ -116,6 +116,7 @@ export const CodeBlock = memo(function CodeBlock({
{codeText && <CopyButton />}
</div>
)}
<CodeContent />
</div>
);

View File

@ -1,3 +1,5 @@
import React from "react";
export function extractCodeText(
node: any,
content: string,
@ -32,7 +34,27 @@ export function extractCodeText(
codeText = formattedCodeLines.join("\n").trim();
} else {
// Fallback if position offsets are not available
codeText = children?.toString() || null;
const extractTextFromReactNode = (node: React.ReactNode): string => {
if (typeof node === "string") return node;
if (typeof node === "number") return String(node);
if (!node) return "";
if (React.isValidElement(node)) {
const children = node.props.children;
if (Array.isArray(children)) {
return children.map(extractTextFromReactNode).join("");
}
return extractTextFromReactNode(children);
}
if (Array.isArray(node)) {
return node.map(extractTextFromReactNode).join("");
}
return "";
};
codeText = extractTextFromReactNode(children);
}
return codeText || "";