From fa888a9e3891e4986a560a51fec5a179b621449c Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Thu, 19 Feb 2026 20:09:08 -0800 Subject: [PATCH] Add markdown rendering utility for bold, italic, and inline code --- src/markdown.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/markdown.ts diff --git a/src/markdown.ts b/src/markdown.ts new file mode 100644 index 0000000..c9eb259 --- /dev/null +++ b/src/markdown.ts @@ -0,0 +1,21 @@ +export function renderMarkdown(text: string): string { + // Extract code spans first so their contents aren't processed as bold/italic + const codeSpans: string[] = [] + let result = text.replace(/`([^`]+)`/g, (_, code) => { + codeSpans.push(code) + return `\x00CODE${codeSpans.length - 1}\x00` + }) + + // Bold: **text** + result = result.replace(/\*\*(.+?)\*\*/g, "\x1b[1m$1\x1b[22m") + + // Italic: *text* + result = result.replace(/\*(.+?)\*/g, "\x1b[3m$1\x1b[23m") + + // Restore code spans as light blue + result = result.replace(/\x00CODE(\d+)\x00/g, (_, i) => { + return `\x1b[94m${codeSpans[parseInt(i)]}\x1b[39m` + }) + + return result +}