mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-04-08 11:58:34 +02:00
Fix code block copy
This commit is contained in:
parent
c9160c705a
commit
d56e6c495a
@ -39,15 +39,25 @@ export function CodeBlock({
|
||||
props.node.position.start.offset,
|
||||
props.node.position.end.offset
|
||||
);
|
||||
codeText = codeText.trim();
|
||||
|
||||
// Remove the language declaration and trailing backticks
|
||||
const codeLines = codeText.split("\n");
|
||||
if (codeLines.length > 1 && codeLines[0].startsWith("```")) {
|
||||
if (
|
||||
codeLines.length > 1 &&
|
||||
(codeLines[0].startsWith("```") || codeLines[0].trim().startsWith("```"))
|
||||
) {
|
||||
codeLines.shift(); // Remove the first line with the language declaration
|
||||
if (codeLines[codeLines.length - 1] === "```") {
|
||||
if (
|
||||
codeLines[codeLines.length - 1] === "```" ||
|
||||
codeLines[codeLines.length - 1]?.trim() === "```"
|
||||
) {
|
||||
codeLines.pop(); // Remove the last line with the trailing backticks
|
||||
}
|
||||
codeText = codeLines.join("\n");
|
||||
|
||||
// remove leading whitespace from each line for nicer copy/paste experience
|
||||
const trimmedCodeLines = codeLines.map((line) => line.trimStart());
|
||||
codeText = trimmedCodeLines.join("\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user