xonecas.io
6533
Yo

yoctomarkdown / commit 90bb466

chore: add streaming test example app

xonecas2026-03-16 90bb466aaa222ff0675d42dab25189ae0ba4d298 parent 65f6dd1

2 files changed

examples/streaming-test.ts+61−0
@@ -0,0 +1,61 @@
1+/**
2+ * Streaming API test app for yoctomarkdown.
3+ *
4+ * Simulates LLM-style character-by-character streaming to verify
5+ * that partial line redraw works without duplicate lines.
6+ *
7+ * Usage: bun examples/streaming-test.ts
8+ */
9+
10+import { createHighlighter } from "../src/index.ts";
11+
12+const markdown = `# Streaming Test
13+
14+This is **bold text** and *italic text* with \`inline code\`.
15+
16+## Code Block
17+
18+\`\`\`
19+function hello() {
20+ console.log("world");
21+}
22+\`\`\`
23+
24+## Lists
25+
26+- First item with **bold**
27+- Second item with \`code\`
28+- Third item
29+
30+1. Ordered one
31+2. Ordered two
32+
33+> A blockquote with *emphasis*
34+
35+---
36+
37+A [link](https://example.com) and some final text.
38+
39+This is a longer paragraph that should cause terminal wrapping when the terminal is narrow enough. It contains **bold words** and *italic words* and \`inline code snippets\` to verify that partial re-rendering handles wrapped lines correctly without duplicating content on screen.
40+`;
41+
42+const delay = (ms: number) => new Promise((r) => setTimeout(r, ms));
43+
44+async function main() {
45+ const highlighter = createHighlighter({ theme: "truecolor" });
46+
47+ // Stream character by character with a small delay to make it visible
48+ for (let i = 0; i < markdown.length; i++) {
49+ const output = highlighter.write(markdown[i]!);
50+ if (output) process.stdout.write(output);
51+ await delay(8);
52+ }
53+
54+ // Flush remaining
55+ const final = highlighter.end();
56+ if (final) process.stdout.write(final);
57+
58+ process.stdout.write("\n");
59+}
60+
61+main();
knip.json+1−1
@@ -1 +1 @@
1-{ "ignoreBinaries": ["tsc", "src/cli.ts"] }
1+{ "ignoreBinaries": ["tsc", "src/cli.ts"], "ignore": ["examples/**"] }