Skip to content

Commit 74d7709

Browse files
committed
fix: markdown renderer use callback functions for chalk formatting
1 parent 1428db9 commit 74d7709

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

src/index.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ const TEMPLATE_DIR = path.resolve(__dirname, "../templates");
1717
/** Simple terminal markdown renderer using chalk */
1818
function renderMarkdown(text: string): string {
1919
return text
20-
.replace(/^### (.+)$/gm, chalk.green.bold(" $1")) // h3
21-
.replace(/^## (.+)$/gm, chalk.green.bold(" $1")) // h2
22-
.replace(/^# (.+)$/gm, chalk.magenta.bold.underline("$1")) // h1
23-
.replace(/\*\*(.+?)\*\*/g, chalk.bold("$1")) // bold
24-
.replace(/\*(.+?)\*/g, chalk.italic("$1")) // italic
25-
.replace(/`([^`]+)`/g, chalk.yellow("$1")) // inline code
26-
.replace(/^- /gm, chalk.dim(" • ")) // list items
27-
.replace(/^(\d+)\. /gm, chalk.dim(" $1. ")) // numbered list
28-
.replace(/^> (.+)$/gm, chalk.gray.italic(" │ $1")) // blockquote
29-
.replace(/^---$/gm, chalk.dim("─".repeat(40))) // hr
30-
.replace(/^```\w*$/gm, chalk.dim("─".repeat(40))); // code fence → hr
20+
.replace(/^### (.+)$/gm, (_m, s) => chalk.green.bold(` ${s}`))
21+
.replace(/^## (.+)$/gm, (_m, s) => chalk.green.bold(` ${s}`))
22+
.replace(/^# (.+)$/gm, (_m, s) => chalk.magenta.bold.underline(s))
23+
.replace(/\*\*(.+?)\*\*/g, (_m, s) => chalk.bold(s))
24+
.replace(/\*(.+?)\*/g, (_m, s) => chalk.italic(s))
25+
.replace(/`([^`]+)`/g, (_m, s) => chalk.yellow(s))
26+
.replace(/^- /gm, " • ")
27+
.replace(/^(\d+)\. /gm, (_m, n) => ` ${n}. `)
28+
.replace(/^> (.+)$/gm, (_m, s) => chalk.gray.italic(`${s}`))
29+
.replace(/^---$/gm, chalk.dim("─".repeat(40)))
30+
.replace(/^```\w*$/gm, chalk.dim("─".repeat(40)));
3131
}
3232

3333
async function main() {

0 commit comments

Comments
 (0)