@f5xc-salesdemos/pi-tui 19.43.0 → 19.43.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/components/markdown.ts +37 -11
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@f5xc-salesdemos/pi-tui",
|
|
4
|
-
"version": "19.43.
|
|
4
|
+
"version": "19.43.2",
|
|
5
5
|
"description": "Terminal User Interface library with differential rendering for efficient text-based applications",
|
|
6
6
|
"homepage": "https://github.com/f5xc-salesdemos/xcsh",
|
|
7
7
|
"author": "Can Boluk",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"fmt": "biome format --write ."
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@f5xc-salesdemos/pi-natives": "19.43.
|
|
41
|
-
"@f5xc-salesdemos/pi-utils": "19.43.
|
|
40
|
+
"@f5xc-salesdemos/pi-natives": "19.43.2",
|
|
41
|
+
"@f5xc-salesdemos/pi-utils": "19.43.2",
|
|
42
42
|
"marked": "^17.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
@@ -2,7 +2,15 @@ import { marked, type Token, type Tokens } from "marked";
|
|
|
2
2
|
import type { SymbolTheme } from "../symbols";
|
|
3
3
|
import { TERMINAL } from "../terminal-capabilities";
|
|
4
4
|
import type { Component } from "../tui";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
applyBackgroundToLine,
|
|
7
|
+
Ellipsis,
|
|
8
|
+
padding,
|
|
9
|
+
replaceTabs,
|
|
10
|
+
truncateToWidth,
|
|
11
|
+
visibleWidth,
|
|
12
|
+
wrapTextWithAnsi,
|
|
13
|
+
} from "../utils";
|
|
6
14
|
|
|
7
15
|
/**
|
|
8
16
|
* Default text styling for markdown content.
|
|
@@ -48,6 +56,12 @@ export interface MarkdownTheme {
|
|
|
48
56
|
* Return null to fall back to fenced code rendering.
|
|
49
57
|
*/
|
|
50
58
|
getMermaidAscii?: (sourceHash: bigint | number) => string | null;
|
|
59
|
+
/**
|
|
60
|
+
* Render a mermaid block (by source) inside the host's framed chrome, clipped to
|
|
61
|
+
* `width`. Returns the framed lines, or null to fall back to `getMermaidAscii` /
|
|
62
|
+
* fenced code rendering. Lets inline ```mermaid blocks match the render_mermaid tool.
|
|
63
|
+
*/
|
|
64
|
+
renderMermaidBlock?: (source: string, width: number) => string[] | null;
|
|
51
65
|
symbols: SymbolTheme;
|
|
52
66
|
}
|
|
53
67
|
|
|
@@ -322,21 +336,33 @@ export class Markdown implements Component {
|
|
|
322
336
|
}
|
|
323
337
|
|
|
324
338
|
case "code": {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
const
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
// Keep the diagram's themed ANSI colors — do not strip.
|
|
332
|
-
for (const asciiLine of ascii.split("\n")) {
|
|
333
|
-
lines.push(asciiLine);
|
|
334
|
-
}
|
|
339
|
+
if (token.lang === "mermaid") {
|
|
340
|
+
// Preferred: render in the host's single F5 frame (themed + clipped),
|
|
341
|
+
// consistent with the render_mermaid tool. The frame clips to width.
|
|
342
|
+
const framed = this.#theme.renderMermaidBlock?.(token.text, width);
|
|
343
|
+
if (framed && framed.length > 0) {
|
|
344
|
+
for (const framedLine of framed) lines.push(framedLine);
|
|
335
345
|
if (nextTokenType && nextTokenType !== "space") {
|
|
336
346
|
lines.push("");
|
|
337
347
|
}
|
|
338
348
|
break;
|
|
339
349
|
}
|
|
350
|
+
|
|
351
|
+
// Fallback: prerendered ASCII. CLIP (not wrap) each row to width so a
|
|
352
|
+
// wide diagram keeps its grid instead of reflowing across lines.
|
|
353
|
+
if (this.#theme.getMermaidAscii) {
|
|
354
|
+
const hash = Bun.hash(token.text.trim());
|
|
355
|
+
const ascii = this.#theme.getMermaidAscii(hash);
|
|
356
|
+
if (ascii) {
|
|
357
|
+
for (const asciiLine of ascii.split("\n")) {
|
|
358
|
+
lines.push(truncateToWidth(asciiLine, width, Ellipsis.Omit));
|
|
359
|
+
}
|
|
360
|
+
if (nextTokenType && nextTokenType !== "space") {
|
|
361
|
+
lines.push("");
|
|
362
|
+
}
|
|
363
|
+
break;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
340
366
|
}
|
|
341
367
|
|
|
342
368
|
const codeIndent = padding(this.#codeBlockIndent);
|