From fc4934af4a06ddcdd385c5c2f117f18f7dcd2780 Mon Sep 17 00:00:00 2001 From: mitchell Date: Wed, 27 May 2026 18:33:14 -0400 Subject: [PATCH] refactor: move wrapAnsi from blockquote/listitem to text tokens --- src/render/markdown.ts | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/render/markdown.ts b/src/render/markdown.ts index 64276c1..71b9f6b 100644 --- a/src/render/markdown.ts +++ b/src/render/markdown.ts @@ -40,24 +40,19 @@ class LmcRenderer extends Renderer { ]; const color = colors[depth - 1] ?? chalk.white; const text = this.parser.parseInline(tokens); - return wrapAnsi( - color.bold(`${"#".repeat(depth)} ${text}\n`), - this.columns, - { trim: false }, - ); + return color.bold(`${"#".repeat(depth)} ${text}\n`); } override paragraph({ tokens }: Tokens.Paragraph) { - const text = this.parser.parseInline(tokens); - return wrapAnsi(`\n${text}\n`, this.columns - 2, { trim: false }); + const text = wrapAnsi(this.parser.parseInline(tokens), this.columns - 4); + return `\n${text}\n`; } override blockquote({ tokens }: Tokens.Blockquote) { - let text = this.parser.parse(tokens).trim(); - if (!text.includes("\n")) text = wrapAnsi(text, this.columns - 2); + const text = this.parser.parse(tokens).trim(); const lines = `\n${text}\n`.split("\n"); const toRender = lines.map((line) => `> ${line}`).join("\n"); - return `${toRender.replaceAll(">", chalk.dim(">"))}\n`; + return `\n${toRender.replaceAll(">", chalk.dim(">"))}\n`; } override code({ text, lang }: Tokens.Code) { @@ -96,8 +91,7 @@ class LmcRenderer extends Renderer { marker = "•"; } - let item = `${marker} ${text}`; - if (!item.includes("\n")) item = wrapAnsi(item, this.columns - 2); + const item = `${marker} ${text}`; return item .split("\n") .map((line) => (line.length > 0 ? ` ${line}` : "")) @@ -167,7 +161,8 @@ class LmcRenderer extends Renderer { override text(token: Tokens.Text | Tokens.Escape) { if (token.type === "text" && token.tokens) { - return this.parser.parseInline(token.tokens); + const parsed = this.parser.parseInline(token.tokens); + return wrapAnsi(parsed, this.columns - 12); } return token.text .replaceAll("$\\rightarrow$", "-->")