mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-04-07 19:38:19 +02:00
Fix code pasting formatting (#2033)
* fix pasting formatting * add back small comments
This commit is contained in:
parent
0261d689dc
commit
876feecd6f
@ -64,9 +64,15 @@ export function CodeBlock({
|
||||
codeLines.pop(); // Remove the last line with the trailing backticks
|
||||
}
|
||||
|
||||
// remove leading whitespace from each line for nicer copy/paste experience
|
||||
const trimmedCodeLines = codeLines.map((line) => line.trimStart());
|
||||
codeText = trimmedCodeLines.join("\n");
|
||||
const minIndent = codeLines
|
||||
.filter((line) => line.trim().length > 0)
|
||||
.reduce((min, line) => {
|
||||
const match = line.match(/^\s*/);
|
||||
return Math.min(min, match ? match[0].length : 0);
|
||||
}, Infinity);
|
||||
|
||||
const formattedCodeLines = codeLines.map((line) => line.slice(minIndent));
|
||||
codeText = formattedCodeLines.join("\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user