fix: wrap multi-line code blocks in pre tag (#5586)

Co-authored-by: openhands <openhands@all-hands.dev>
This commit is contained in:
Robert Brennan 2024-12-16 16:30:06 -05:00 committed by GitHub
parent 4998b5de32
commit 50478c7d21
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -17,19 +17,38 @@ export function code({
const match = /language-(\w+)/.exec(className || ""); // get the language
if (!match) {
const isMultiline = String(children).includes("\n");
if (!isMultiline) {
return (
<code
className={className}
style={{
backgroundColor: "#2a3038",
padding: "0.2em 0.4em",
borderRadius: "4px",
color: "#e6edf3",
border: "1px solid #30363d",
}}
>
{children}
</code>
);
}
return (
<code
className={className}
<pre
style={{
backgroundColor: "#2a3038",
padding: "0.2em 0.4em",
padding: "1em",
borderRadius: "4px",
color: "#e6edf3",
border: "1px solid #30363d",
overflow: "auto",
}}
>
{children}
</code>
<code className={className}>{String(children).replace(/\n$/, "")}</code>
</pre>
);
}