xonecas.io
64875
Mc

mini-coder / commit fadbc49

feat: add streaming markdown syntax highlighting

Integrates yoctomarkdown for real-time syntax highlighting of streamed markdown content. Updates stream rendering logic and adjusts tests to accommodate ANSI output.

xonecas2026-03-15 fadbc4995b3b97be84a1acbc2e4e25029557dada parent a20b8dd

3 files changed

package.json+1−0
@@ -28,6 +28,7 @@
2828 "ai": "^6.0.127",
2929 "diff": "^8.0.3",
3030 "yoctocolors": "^2.1.2",
31+ "yoctomarkdown": "^0.0.1",
3132 "zod": "^4.3.6"
3233 },
3334 "devDependencies": {
src/cli/stream-render-content.ts+14−1
@@ -1,3 +1,7 @@
1+import {
2+ createHighlighter,
3+ type Highlighter,
4+} from "yoctomarkdown/src/index.ts";
15 import { G, write, writeln } from "./output.ts";
26 import type { Spinner } from "./spinner.ts";
37
@@ -5,6 +9,7 @@ export class StreamRenderContent {
59 private inText = false;
610 private accumulatedText = "";
711 private accumulatedReasoning = "";
12+ private highlighter: Highlighter | undefined;
813
914 constructor(private readonly spinner: Spinner) {}
1015
@@ -31,10 +36,14 @@ export class StreamRenderContent {
3136 if (renderedVisibleOutput) writeln();
3237 write(`${G.reply} `);
3338 this.inText = true;
39+ this.highlighter = createHighlighter();
3440 }
3541 this.accumulatedText += text;
3642 this.spinner.stop();
37- write(text);
43+ if (this.highlighter) {
44+ const colored = this.highlighter.write(text);
45+ if (colored) write(colored);
46+ }
3847 }
3948
4049 appendReasoningDelta(delta: string | undefined): string {
@@ -54,6 +63,10 @@ export class StreamRenderContent {
5463
5564 flushOpenContent(): void {
5665 if (!this.inText) return;
66+ if (this.highlighter) {
67+ const finalColored = this.highlighter.end();
68+ if (finalColored) write(finalColored);
69+ }
5770 writeln();
5871 this.inText = false;
5972 }
src/cli/stream-render.test.ts+0−3
@@ -252,7 +252,6 @@ describe("renderTurn", () => {
252252 // Streaming now prioritizes immediate output stability over end-of-line markdown
253253 // rewrite, so raw markdown markers are preserved in partial lines.
254254 expect(simulateTerminal(stdout)).toBe("◆ **bold** 👩🏽‍💻\n");
255- expect(hasAnsi(stdout, "[1m")).toBe(false);
256255 });
257256
258257 test("leaves fenced markdown plain across streamed lines", async () => {
@@ -268,8 +267,6 @@ describe("renderTurn", () => {
268267 );
269268
270269 expect(strip(stdout)).toBe("◆ ```ts\nconst emoji = '👩🏽‍💻';\n```\n\n");
271- expect(hasAnsi(stdout, "[2m")).toBe(false);
272- expect(hasAnsi(stdout, "[33m")).toBe(false);
273270 });
274271 test("can hide reasoning output while still accumulating reasoning text", async () => {
275272 captureStdout();