mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-06-14 10:00:53 +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
|
codeLines.pop(); // Remove the last line with the trailing backticks
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove leading whitespace from each line for nicer copy/paste experience
|
const minIndent = codeLines
|
||||||
const trimmedCodeLines = codeLines.map((line) => line.trimStart());
|
.filter((line) => line.trim().length > 0)
|
||||||
codeText = trimmedCodeLines.join("\n");
|
.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