@f5-sales-demo/pi-tui 23.8.0 → 23.9.0
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 +34 -10
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@f5-sales-demo/pi-tui",
|
|
4
|
-
"version": "23.
|
|
4
|
+
"version": "23.9.0",
|
|
5
5
|
"description": "Terminal User Interface library with differential rendering for efficient text-based applications",
|
|
6
6
|
"homepage": "https://github.com/f5-sales-demo/xcsh",
|
|
7
7
|
"author": "Can Boluk",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"fmt": "biome format --write ."
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@f5-sales-demo/pi-natives": "23.
|
|
41
|
-
"@f5-sales-demo/pi-utils": "23.
|
|
40
|
+
"@f5-sales-demo/pi-natives": "23.9.0",
|
|
41
|
+
"@f5-sales-demo/pi-utils": "23.9.0",
|
|
42
42
|
"marked": "18.0.11"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as path from "node:path";
|
|
2
2
|
import { pathToFileURL } from "node:url";
|
|
3
|
+
import { isCodeBlockComplete, presentCode, wrapCodeLine } from "@f5-sales-demo/pi-utils/code-presentation";
|
|
3
4
|
import { Marked, type Token, type TokenizerExtension, type Tokens } from "marked";
|
|
4
5
|
import { renderLatex } from "../latex";
|
|
5
6
|
import type { SymbolTheme } from "../symbols";
|
|
@@ -277,6 +278,7 @@ export interface MarkdownTheme {
|
|
|
277
278
|
code: (text: string) => string;
|
|
278
279
|
codeBlock: (text: string) => string;
|
|
279
280
|
codeBlockBorder: (text: string) => string;
|
|
281
|
+
codeBlockBackground?: (text: string) => string;
|
|
280
282
|
quote: (text: string) => string;
|
|
281
283
|
quoteBorder: (text: string) => string;
|
|
282
284
|
hr: (text: string) => string;
|
|
@@ -700,19 +702,41 @@ export class Markdown implements Component {
|
|
|
700
702
|
}
|
|
701
703
|
}
|
|
702
704
|
|
|
703
|
-
const
|
|
704
|
-
|
|
705
|
-
|
|
705
|
+
const view = presentCode(
|
|
706
|
+
token.text,
|
|
707
|
+
token.lang,
|
|
708
|
+
isCodeBlockComplete(token.raw, token.codeBlockStyle === "indented"),
|
|
709
|
+
);
|
|
710
|
+
const indentWidth = Math.min(this.#codeBlockIndent, Math.max(0, width - 5));
|
|
711
|
+
const prefixWidth = Math.min(width - 1, indentWidth + 4);
|
|
712
|
+
const available = Math.max(1, width - prefixWidth);
|
|
706
713
|
const codeLines = this.#theme.highlightCode
|
|
707
|
-
? this.#theme.highlightCode(
|
|
708
|
-
:
|
|
714
|
+
? this.#theme.highlightCode(view.display, view.language)
|
|
715
|
+
: view.display.split("\n").map(line => this.#theme.codeBlock(line));
|
|
709
716
|
for (const codeLine of codeLines) {
|
|
710
717
|
const displayed = replaceTabs(codeLine);
|
|
711
|
-
const
|
|
712
|
-
const
|
|
713
|
-
const
|
|
714
|
-
|
|
715
|
-
|
|
718
|
+
const plain = Bun.stripANSI(displayed);
|
|
719
|
+
const leading = /^ */.exec(plain)?.[0].length ?? 0;
|
|
720
|
+
const sourceIndent = leading < available / 2 ? leading : 0;
|
|
721
|
+
const body = plain.slice(sourceIndent);
|
|
722
|
+
for (const part of wrapCodeLine(body, available - sourceIndent, visibleWidth)) {
|
|
723
|
+
const a = visibleWidth(plain.slice(0, sourceIndent + part.start));
|
|
724
|
+
const b = visibleWidth(plain.slice(0, sourceIndent + part.end));
|
|
725
|
+
const gutter =
|
|
726
|
+
this.#theme.symbols.boxSharp.vertical +
|
|
727
|
+
" " +
|
|
728
|
+
(part.continuation ? this.#theme.symbols.boxSharp.teeRight : " ") +
|
|
729
|
+
" ";
|
|
730
|
+
const prefix = padding(indentWidth) + this.#theme.codeBlockBorder(gutter);
|
|
731
|
+
const visual =
|
|
732
|
+
sliceWithWidth(prefix, 0, prefixWidth, true).text +
|
|
733
|
+
padding(sourceIndent) +
|
|
734
|
+
sliceWithWidth(displayed, a, b - a, true).text;
|
|
735
|
+
lines.push(
|
|
736
|
+
this.#theme.codeBlockBackground
|
|
737
|
+
? applyBackgroundToLine(visual, width, this.#theme.codeBlockBackground)
|
|
738
|
+
: visual,
|
|
739
|
+
);
|
|
716
740
|
}
|
|
717
741
|
}
|
|
718
742
|
if (nextTokenType && nextTokenType !== "space") {
|