xonecas.io
64875
Mc

mini-coder / commit a23c8d8

fix(tui): self-contained spans, and no blank row for an empty fence

sgr() skipped fg/bg when a style named none, so an attribute-only span
(text.strong, text.emphasis, text.uri) kept whatever color was set last:
`a **b** c` painted `b` in the `**` marker's blue. Spans now carry their
defaults, so the innermost style wins as paint() documents.

A fence with an empty body emitted one blank row: joining an empty body
gives "" and "".split("\n") is [""].

xonecas2026-09-23 a23c8d8a3d4ae6af3775f02df137339e9b3d3a43 parent e80f67a

2 files changed

src/highlight.ts+6−2
@@ -150,6 +150,10 @@ function parse(syntax: Syntax, text: string): Parser.SyntaxNode {
150150 return syntax.parser.parse(text).rootNode;
151151 }
152152
153+/**
154+ * A style's own attributes, with the defaults spelled out: a span that names no
155+ * color must not inherit the color of the span or token before it.
156+ */
153157 function sgr(style: Style): string {
154158 const channel = (code: number, hex: string): string =>
155159 `${code};2;${[1, 3, 5].map((i) => Number.parseInt(hex.slice(i, i + 2), 16)).join(";")};`;
@@ -157,8 +161,8 @@ function sgr(style: Style): string {
157161 if (style.bold) out += "1;";
158162 if (style.italic) out += "3;";
159163 if (style.underline) out += "4;";
160- if (style.fg !== undefined) out += channel(38, style.fg);
161- if (style.bg !== undefined) out += channel(48, style.bg);
164+ out += style.fg === undefined ? "39;" : channel(38, style.fg);
165+ out += style.bg === undefined ? "49;" : channel(48, style.bg);
162166 return `${out.slice(0, -1)}m`;
163167 }
164168
src/tui/stream.ts+4−2
@@ -110,8 +110,10 @@ export class MarkdownStream implements StreamRenderer {
110110 const fence = this.fence!;
111111 this.fence = null;
112112 const lines: BodyLine[] = [{ text: highlightMarkdown(fence.lines.shift()!) }];
113- for (const line of highlightCode(fence.info, fence.lines.join("\n")).split("\n")) {
114- lines.push({ text: line });
113+ if (fence.lines.length > 0) {
114+ for (const line of highlightCode(fence.info, fence.lines.join("\n")).split("\n")) {
115+ lines.push({ text: line });
116+ }
115117 }
116118 if (closing !== null) lines.push({ text: highlightMarkdown(closing) });
117119 return lines;