p2: add quote and code-block text formatting
All checks were successful
CI / test (push) Successful in 20s
All checks were successful
CI / test (push) Successful in 20s
This commit is contained in:
@@ -108,5 +108,28 @@ function parseInline(text: string): string {
|
||||
}
|
||||
|
||||
export function formatMessageHtml(text: string): string {
|
||||
return parseInline(text);
|
||||
const blocks: string[] = [];
|
||||
const parts = text.split(/```/);
|
||||
for (let i = 0; i < parts.length; i += 1) {
|
||||
const part = parts[i];
|
||||
const isCode = i % 2 === 1;
|
||||
if (isCode) {
|
||||
const value = escapeHtml(part.replace(/^\n+|\n+$/g, ""));
|
||||
blocks.push(`<pre class="my-1 overflow-x-auto rounded-lg bg-slate-900/90 px-2 py-1.5 text-[12px]"><code>${value}</code></pre>`);
|
||||
continue;
|
||||
}
|
||||
const lines = part.split("\n");
|
||||
for (let lineIndex = 0; lineIndex < lines.length; lineIndex += 1) {
|
||||
const line = lines[lineIndex];
|
||||
if (line.startsWith("> ")) {
|
||||
blocks.push(`<blockquote class="my-1 border-l-2 border-sky-400/80 bg-slate-800/60 px-2 py-1 text-sm">${parseInline(line.slice(2))}</blockquote>`);
|
||||
} else {
|
||||
blocks.push(parseInline(line));
|
||||
}
|
||||
if (lineIndex < lines.length - 1) {
|
||||
blocks.push("<br/>");
|
||||
}
|
||||
}
|
||||
}
|
||||
return blocks.join("");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user