@tooee/renderers 0.7.3 → 0.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.
Files changed (171) hide show
  1. package/dist/chooser/choose-filter.d.ts +13 -0
  2. package/dist/chooser/choose-filter.d.ts.map +1 -0
  3. package/dist/chooser/choose-filter.js +22 -0
  4. package/dist/chooser/choose-filter.js.map +1 -0
  5. package/dist/chooser/choose-highlighted-text.d.ts +9 -0
  6. package/dist/chooser/choose-highlighted-text.d.ts.map +1 -0
  7. package/dist/chooser/choose-highlighted-text.js +32 -0
  8. package/dist/chooser/choose-highlighted-text.js.map +1 -0
  9. package/dist/chooser/choose-list.d.ts +29 -0
  10. package/dist/chooser/choose-list.d.ts.map +1 -0
  11. package/dist/chooser/choose-list.js +66 -0
  12. package/dist/chooser/choose-list.js.map +1 -0
  13. package/dist/chooser/choose-store.d.ts +58 -0
  14. package/dist/chooser/choose-store.d.ts.map +1 -0
  15. package/dist/chooser/choose-store.js +102 -0
  16. package/dist/chooser/choose-store.js.map +1 -0
  17. package/dist/chooser/chooser.d.ts +18 -0
  18. package/dist/chooser/chooser.d.ts.map +1 -0
  19. package/dist/chooser/chooser.js +25 -0
  20. package/dist/chooser/chooser.js.map +1 -0
  21. package/dist/chooser/fuzzy.d.ts +9 -0
  22. package/dist/chooser/fuzzy.d.ts.map +1 -0
  23. package/dist/chooser/fuzzy.js +5 -0
  24. package/dist/chooser/fuzzy.js.map +1 -0
  25. package/dist/chooser/source.d.ts +5 -0
  26. package/dist/chooser/source.d.ts.map +1 -0
  27. package/dist/chooser/source.js +26 -0
  28. package/dist/chooser/source.js.map +1 -0
  29. package/dist/chooser/types.d.ts +22 -0
  30. package/dist/chooser/types.d.ts.map +1 -0
  31. package/dist/chooser/types.js +2 -0
  32. package/dist/chooser/types.js.map +1 -0
  33. package/dist/chooser/use-choose.d.ts +84 -0
  34. package/dist/chooser/use-choose.d.ts.map +1 -0
  35. package/dist/chooser/use-choose.js +382 -0
  36. package/dist/chooser/use-choose.js.map +1 -0
  37. package/dist/code-blocks.d.ts +2 -1
  38. package/dist/code-blocks.d.ts.map +1 -1
  39. package/dist/code-blocks.js +20 -18
  40. package/dist/code-blocks.js.map +1 -1
  41. package/dist/code-view.d.ts +2 -1
  42. package/dist/code-view.d.ts.map +1 -1
  43. package/dist/code-view.js.map +1 -1
  44. package/dist/command-palette.d.ts +2 -1
  45. package/dist/command-palette.d.ts.map +1 -1
  46. package/dist/command-palette.js +15 -76
  47. package/dist/command-palette.js.map +1 -1
  48. package/dist/context-menu.d.ts +2 -1
  49. package/dist/context-menu.d.ts.map +1 -1
  50. package/dist/context-menu.js +50 -15
  51. package/dist/context-menu.js.map +1 -1
  52. package/dist/index.d.ts +19 -3
  53. package/dist/index.d.ts.map +1 -1
  54. package/dist/index.js +9 -1
  55. package/dist/index.js.map +1 -1
  56. package/dist/markdown/blocks/blockquote.d.ts +11 -0
  57. package/dist/markdown/blocks/blockquote.d.ts.map +1 -0
  58. package/dist/markdown/blocks/blockquote.js +26 -0
  59. package/dist/markdown/blocks/blockquote.js.map +1 -0
  60. package/dist/markdown/blocks/flat-block.d.ts +20 -0
  61. package/dist/markdown/blocks/flat-block.d.ts.map +1 -0
  62. package/dist/markdown/blocks/flat-block.js +52 -0
  63. package/dist/markdown/blocks/flat-block.js.map +1 -0
  64. package/dist/markdown/blocks/heading.d.ts +11 -0
  65. package/dist/markdown/blocks/heading.d.ts.map +1 -0
  66. package/dist/markdown/blocks/heading.js +23 -0
  67. package/dist/markdown/blocks/heading.js.map +1 -0
  68. package/dist/markdown/blocks/horizontal-rule.d.ts +7 -0
  69. package/dist/markdown/blocks/horizontal-rule.d.ts.map +1 -0
  70. package/dist/markdown/blocks/horizontal-rule.js +5 -0
  71. package/dist/markdown/blocks/horizontal-rule.js.map +1 -0
  72. package/dist/markdown/blocks/list-line.d.ts +10 -0
  73. package/dist/markdown/blocks/list-line.d.ts.map +1 -0
  74. package/dist/markdown/blocks/list-line.js +21 -0
  75. package/dist/markdown/blocks/list-line.js.map +1 -0
  76. package/dist/markdown/blocks/paragraph.d.ts +12 -0
  77. package/dist/markdown/blocks/paragraph.d.ts.map +1 -0
  78. package/dist/markdown/blocks/paragraph.js +27 -0
  79. package/dist/markdown/blocks/paragraph.js.map +1 -0
  80. package/dist/markdown/blocks/table.d.ts +7 -0
  81. package/dist/markdown/blocks/table.d.ts.map +1 -0
  82. package/dist/markdown/blocks/table.js +30 -0
  83. package/dist/markdown/blocks/table.js.map +1 -0
  84. package/dist/markdown/chunks.d.ts +5 -0
  85. package/dist/markdown/chunks.d.ts.map +1 -0
  86. package/dist/markdown/chunks.js +29 -0
  87. package/dist/markdown/chunks.js.map +1 -0
  88. package/dist/markdown/inline.d.ts +8 -0
  89. package/dist/markdown/inline.d.ts.map +1 -0
  90. package/dist/markdown/inline.js +27 -0
  91. package/dist/markdown/inline.js.map +1 -0
  92. package/dist/markdown/links.d.ts +11 -0
  93. package/dist/markdown/links.d.ts.map +1 -0
  94. package/dist/markdown/links.js +107 -0
  95. package/dist/markdown/links.js.map +1 -0
  96. package/dist/markdown/plain-text.d.ts +4 -0
  97. package/dist/markdown/plain-text.d.ts.map +1 -0
  98. package/dist/markdown/plain-text.js +21 -0
  99. package/dist/markdown/plain-text.js.map +1 -0
  100. package/dist/markdown/tokens.d.ts +32 -0
  101. package/dist/markdown/tokens.d.ts.map +1 -0
  102. package/dist/markdown/tokens.js +25 -0
  103. package/dist/markdown/tokens.js.map +1 -0
  104. package/dist/markdown/visit-inline.d.ts +17 -0
  105. package/dist/markdown/visit-inline.d.ts.map +1 -0
  106. package/dist/markdown/visit-inline.js +61 -0
  107. package/dist/markdown/visit-inline.js.map +1 -0
  108. package/dist/markdown-blocks.d.ts.map +1 -1
  109. package/dist/markdown-blocks.js +6 -4
  110. package/dist/markdown-blocks.js.map +1 -1
  111. package/dist/markdown-images.d.ts.map +1 -1
  112. package/dist/markdown-images.js +14 -5
  113. package/dist/markdown-images.js.map +1 -1
  114. package/dist/markdown-view.d.ts +10 -32
  115. package/dist/markdown-view.d.ts.map +1 -1
  116. package/dist/markdown-view.js +9 -468
  117. package/dist/markdown-view.js.map +1 -1
  118. package/dist/mermaid.d.ts +5 -4
  119. package/dist/mermaid.d.ts.map +1 -1
  120. package/dist/mermaid.js +5 -5
  121. package/dist/mermaid.js.map +1 -1
  122. package/dist/parsers.d.ts +6 -13
  123. package/dist/parsers.d.ts.map +1 -1
  124. package/dist/parsers.js +66 -46
  125. package/dist/parsers.js.map +1 -1
  126. package/dist/row-document-renderable.d.ts +7 -6
  127. package/dist/row-document-renderable.d.ts.map +1 -1
  128. package/dist/row-document-renderable.js +2 -7
  129. package/dist/row-document-renderable.js.map +1 -1
  130. package/dist/table-types.d.ts +4 -0
  131. package/dist/table-types.d.ts.map +1 -1
  132. package/dist/table.d.ts +4 -1
  133. package/dist/table.d.ts.map +1 -1
  134. package/dist/table.js +30 -23
  135. package/dist/table.js.map +1 -1
  136. package/package.json +9 -5
  137. package/src/chooser/choose-filter.tsx +66 -0
  138. package/src/chooser/choose-highlighted-text.tsx +49 -0
  139. package/src/chooser/choose-list.tsx +159 -0
  140. package/src/chooser/choose-store.ts +147 -0
  141. package/src/chooser/chooser.tsx +80 -0
  142. package/src/chooser/fuzzy.ts +13 -0
  143. package/src/chooser/source.ts +36 -0
  144. package/src/chooser/types.ts +28 -0
  145. package/src/chooser/use-choose.ts +540 -0
  146. package/src/code-blocks.tsx +28 -26
  147. package/src/code-view.tsx +2 -1
  148. package/src/command-palette.tsx +49 -137
  149. package/src/context-menu.tsx +54 -15
  150. package/src/index.ts +46 -3
  151. package/src/markdown/blocks/blockquote.tsx +53 -0
  152. package/src/markdown/blocks/flat-block.tsx +119 -0
  153. package/src/markdown/blocks/heading.tsx +53 -0
  154. package/src/markdown/blocks/horizontal-rule.tsx +16 -0
  155. package/src/markdown/blocks/list-line.tsx +52 -0
  156. package/src/markdown/blocks/paragraph.tsx +90 -0
  157. package/src/markdown/blocks/table.tsx +55 -0
  158. package/src/markdown/chunks.ts +42 -0
  159. package/src/markdown/inline.tsx +45 -0
  160. package/src/markdown/links.ts +133 -0
  161. package/src/markdown/plain-text.ts +22 -0
  162. package/src/markdown/tokens.ts +53 -0
  163. package/src/markdown/visit-inline.ts +82 -0
  164. package/src/markdown-blocks.ts +6 -4
  165. package/src/markdown-images.ts +15 -6
  166. package/src/markdown-view.tsx +20 -845
  167. package/src/mermaid.ts +11 -9
  168. package/src/parsers.ts +86 -62
  169. package/src/row-document-renderable.ts +13 -15
  170. package/src/table-types.ts +5 -0
  171. package/src/table.tsx +36 -30
@@ -67,14 +67,23 @@ export const splitMarkdownImages = function splitMarkdownImages(tokens) {
67
67
  }
68
68
  };
69
69
  for (const token of tokens) {
70
- if (token.type === "image" && "href" in token && typeof token.href === "string") {
70
+ if (token.type === "image") {
71
+ // SAFETY: Marked creates an Image token for the adjacent token.type branch.
72
+ // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- Marked's broad Token fallback prevents discriminator narrowing
73
+ const imageToken = token;
71
74
  flushText();
72
- const alt = "text" in token && typeof token.text === "string" ? token.text : undefined;
73
- result.push({ alt: alt === "" ? undefined : alt, source: token.href, type: "image" });
75
+ result.push({
76
+ alt: imageToken.text === "" ? undefined : imageToken.text,
77
+ source: imageToken.href,
78
+ type: "image",
79
+ });
74
80
  continue;
75
81
  }
76
- if (token.type === "text" && "text" in token && typeof token.text === "string") {
77
- const parts = splitTextToken(token.text);
82
+ if (token.type === "text") {
83
+ // SAFETY: Marked creates a Text token for the adjacent token.type branch.
84
+ // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- Marked's broad Token fallback prevents discriminator narrowing
85
+ const textToken = token;
86
+ const parts = splitTextToken(textToken.text);
78
87
  for (const part of parts) {
79
88
  if (part.type === "text") {
80
89
  pendingText.push(...part.tokens);
@@ -1 +1 @@
1
- {"version":3,"file":"markdown-images.js","sourceRoot":"","sources":["../src/markdown-images.ts"],"names":[],"mappings":"AAAA,OAA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AC;gBACzB,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;oBACzB,WAAW,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;gBACnC,CAAC;qBAAM,CAAC;oBACN,SAAS,EAAE,CAAC;oBACZ,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACpB,CAAC;YACH,CAAC;YACD,SAAS;QACX,CAAC;QACD,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC1B,CAAC;IACD,SAAS,EAAE,CAAC;IACZ,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAEF,4EAA4E;AAC5E,MAAM,CAAC,MAAM,0BAA0B,GAAG,SAAS,0BAA0B,CAC3E,MAAc,EACd,QAAiB;IAEjB,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QACvD,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,GAAG,EAAE,EAAE,MAAM,CAAC,CAAC;AACzD,CAAC,CAAC"}
@@ -1,16 +1,14 @@
1
- import type { Token } from "marked";
2
1
  import type { ReactNode, RefObject } from "react";
3
2
  import type { TextBufferRenderable } from "@opentui/core";
4
- import type { DocumentBindings } from "./document-bindings.js";
5
3
  import type { CodeBlockRenderer } from "./code-blocks.js";
4
+ import type { DocumentBindings } from "./document-bindings.js";
6
5
  import type { FlatBlock } from "./markdown-blocks.js";
6
+ import type { MarkdownLinkHandler } from "./markdown/links.js";
7
7
  import "./row-document.js";
8
8
  import "./text-table.js";
9
- export type MarkdownLinkHandler = (href: string) => unknown;
10
- export interface InlineLinkPosition {
11
- line: number;
12
- column: number;
13
- }
9
+ export { inlineLinkAtPosition } from "./markdown/links.js";
10
+ export type { InlineLinkPosition, MarkdownLinkHandler } from "./markdown/links.js";
11
+ type CodeBlockRendererRegistry = Record<string, CodeBlockRenderer>;
14
12
  interface MarkdownViewProps {
15
13
  content: string;
16
14
  /**
@@ -23,7 +21,7 @@ interface MarkdownViewProps {
23
21
  showLineNumbers?: boolean;
24
22
  /**
25
23
  * Binds the row document to a document controller: its ref, the decoration
26
- * layers to paint, and the mouse handler. Rows are flattened *block* indices —
24
+ * layers to paint, and the mouse handler. Rows are flattened *block* indices,
27
25
  * the same unit `j`/`k` move between and copy operates on. Omit it to render
28
26
  * a static, non-interactive document.
29
27
  *
@@ -34,34 +32,14 @@ interface MarkdownViewProps {
34
32
  * stops propagation.
35
33
  */
36
34
  document?: DocumentBindings;
37
- /**
38
- * Registry of horizontally scrollable blocks, keyed by block index. Blocks
39
- * that can overflow horizontally (mermaid diagrams and code blocks)
40
- * register their text-buffer renderable here so the owning subview can
41
- * drive horizontal panning (`scrollX`) for the block under the nav cursor
42
- * (h/l in cursor mode).
43
- */
35
+ /** Registry of horizontally scrollable blocks, keyed by block index. */
44
36
  hScrollableBlocksRef?: RefObject<Map<number, TextBufferRenderable>>;
45
- /**
46
- * Custom renderers for fenced code blocks, keyed by fence type. A fence's
47
- * type is the first whitespace-separated word of its info string, matched
48
- * case-insensitively. Entries are merged over the built-in defaults
49
- * (currently `mermaid`), so built-ins can be overridden. Unmatched types —
50
- * and renderers that return `null` or throw — fall back to the default
51
- * syntax-highlighted code block.
52
- */
53
- codeBlockRenderers?: Record<string, CodeBlockRenderer>;
54
- /**
55
- * Called when the primary mouse button activates inline Markdown link text.
56
- * Return `true` when the host handled the href; handled clicks do not bubble
57
- * to document row selection. Unhandled links retain their native OSC-8 href.
58
- */
37
+ /** Custom fenced-code renderers merged over the built-in defaults. */
38
+ codeBlockRenderers?: CodeBlockRendererRegistry;
39
+ /** Called when the primary mouse button activates inline Markdown link text. */
59
40
  onLinkActivate?: MarkdownLinkHandler;
60
41
  /** Directory used to resolve relative standard Markdown and Obsidian image embeds. */
61
42
  imageBasePath?: string;
62
43
  }
63
- /** Resolve a rendered text position to the Markdown link occupying that cell. */
64
- export declare const inlineLinkAtPosition: (tokens: readonly Token[], position: InlineLinkPosition, initialColumn?: number) => string | null;
65
44
  export declare const MarkdownView: ({ content, blocks: providedBlocks, showLineNumbers, document, hScrollableBlocksRef, codeBlockRenderers, onLinkActivate, imageBasePath, }: MarkdownViewProps) => ReactNode;
66
- export {};
67
45
  //# sourceMappingURL=markdown-view.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"markdown-view.d.ts","sourceRoot":"","sources":["../src/markdown-view.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAU,MAAM,QAAQ,CAAC;AAG5C,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AASlD,OAAO,KAAK,EAEV,oBAAoB,EAKrB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAO/D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAE1D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGtD,OAAO,mBAAmB,CAAC;AAC3B,OAAO,iBAAiB,CAAC;AAMzB,MAAM,MAAM,mBAAmB,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;AAE5D,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB;AAOD,UAAU,iBAAiB;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,SAAS,SAAS,EAAE,CAAC;IAC9B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,EAAE,gBAAgB,CAAC;IAC5B;;;;;;OAMG;IACH,oBAAoB,CAAC,EAAE,SAAS,CAAC,GAAG,CAAC,MAAM,EAAE,oBAAo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;IAC1B;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,EAAE,gBAAgB,CAAC;IAC5B,wEAAwE;IACxE,oBAAoB,CAAC,EAAE,SAAS,CAAC,GAAG,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC,CAAC;IACpE,sEAAsE;IACtE,kBAAkB,CAAC,EAAE,yBAAyB,CAAC;IAC/C,gFAAgF;IAChF,cAAc,CAAC,EAAE,mBAAmB,CAAC;IACrC,sFAAsF;IACtF,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAKD,eAAO,MAAM,YAAY,6IAStB,iBAAiB,KAAG,SAuEtB,CAAC"}
@@ -1,136 +1,15 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "@opentui/react/jsx-runtime";
2
- import { useEffect, useMemo, useState } from "react";
1
+ import { jsx as _jsx } from "@opentui/react/jsx-runtime";
2
+ import { useMemo } from "react";
3
3
  import { useTerminalDimensions } from "@opentui/react";
4
4
  import { useTheme } from "@tooee/themes";
5
- import { bold as boldChunk, italic as italicChunk, underline as underlineChunk, parseColor, } from "@opentui/core";
5
+ import { DEFAULT_CODE_BLOCK_RENDERERS } from "./code-blocks.js";
6
+ import { flattenMarkdown } from "./markdown-blocks.js";
7
+ import { FlatBlockRenderer } from "./markdown/blocks/flat-block.js";
6
8
  import { DEFAULT_SIGN_COLUMN_WIDTH, computeRowDocumentGutterWidth, } from "./row-document-renderable.js";
7
9
  import { useGutterPalette } from "./use-gutter-palette.js";
8
- import { CodeBlock, DEFAULT_CODE_BLOCK_RENDERERS } from "./code-blocks.js";
9
- import { checkboxMarker, flattenMarkdown } from "./markdown-blocks.js";
10
- import { resolveMarkdownImageSource, splitMarkdownImages } from "./markdown-images.js";
11
10
  import "./row-document.js";
12
11
  import "./text-table.js";
13
- /** Markdown soft line endings separate prose words without forcing a rendered break. */
14
- const normalizeSoftLineEndings = function normalizeSoftLineEndings(value) {
15
- return value.replaceAll("\n", " ");
16
- };
17
- // ---------------------------------------------------------------------------
18
- // Inline link hit testing
19
- // ---------------------------------------------------------------------------
20
- /** Resolve a rendered text position to the Markdown link occupying that cell. */
21
- export const inlineLinkAtPosition = function inlineLinkAtPosition(tokens, position, initialColumn = 0) {
22
- let line = 0;
23
- let column = initialColumn;
24
- let found = null;
25
- const advanceText = (value, href) => {
26
- const parts = value.split("\n");
27
- for (const [index, part] of parts.entries()) {
28
- const width = Bun.stringWidth(part);
29
- if (href !== undefined &&
30
- line === position.line &&
31
- position.column >= column &&
32
- position.column < column + width) {
33
- found = href;
34
- }
35
- column += width;
36
- if (index < parts.length - 1) {
37
- line += 1;
38
- column = 0;
39
- }
40
- }
41
- };
42
- const visit = (items, href) => {
43
- for (const token of items) {
44
- if (found !== null) {
45
- return;
46
- }
47
- switch (token.type) {
48
- case "text": {
49
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- Deferred(lint-sweep): marked token narrowing; schema-based validation in a later sweep
50
- advanceText(normalizeSoftLineEndings(token.text), href);
51
- break;
52
- }
53
- case "link": {
54
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- Deferred(lint-sweep): marked token narrowing; schema-based validation in a later sweep
55
- const link = token;
56
- visit(link.tokens, link.href);
57
- break;
58
- }
59
- case "strong": {
60
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- Deferred(lint-sweep): marked token narrowing; schema-based validation in a later sweep
61
- visit(token.tokens, href);
62
- break;
63
- }
64
- case "em": {
65
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- Deferred(lint-sweep): marked token narrowing; schema-based validation in a later sweep
66
- visit(token.tokens, href);
67
- break;
68
- }
69
- case "del": {
70
- advanceText("~", href);
71
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- Deferred(lint-sweep): marked token narrowing; schema-based validation in a later sweep
72
- visit(token.tokens, href);
73
- advanceText("~", href);
74
- break;
75
- }
76
- case "codespan": {
77
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- Deferred(lint-sweep): marked token narrowing; schema-based validation in a later sweep
78
- advanceText(` ${token.text} `, href);
79
- break;
80
- }
81
- case "br": {
82
- advanceText("\n", href);
83
- break;
84
- }
85
- case "space": {
86
- advanceText(" ", href);
87
- break;
88
- }
89
- default: {
90
- if ("text" in token && typeof token.text === "string") {
91
- advanceText(token.text, href);
92
- }
93
- }
94
- }
95
- }
96
- };
97
- visit(tokens);
98
- return found;
99
- };
100
- const linkMouseHandler = function linkMouseHandler(tokens, onLinkActivate, initialColumn = 0) {
101
- if (onLinkActivate === undefined) {
102
- return undefined;
103
- }
104
- return (event) => {
105
- if (event.button !== 0) {
106
- return;
107
- }
108
- const { target } = event;
109
- if (target === null || target === undefined || !("lineInfo" in target)) {
110
- return;
111
- }
112
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- OpenTUI mouse targets are renderables; lineInfo narrows this to a text buffer at the framework boundary
113
- const text = target;
114
- const visualLine = event.y - text.y;
115
- const sourceLine = text.lineInfo.lineSources[visualLine];
116
- const startColumn = text.lineInfo.lineStartCols[visualLine];
117
- if (sourceLine === undefined || startColumn === undefined) {
118
- return;
119
- }
120
- const href = inlineLinkAtPosition(tokens, {
121
- column: startColumn + event.x - text.x,
122
- line: sourceLine,
123
- }, initialColumn);
124
- if (href === null || onLinkActivate(href) !== true) {
125
- return;
126
- }
127
- event.preventDefault();
128
- event.stopPropagation();
129
- };
130
- };
131
- // ---------------------------------------------------------------------------
132
- // Component
133
- // ---------------------------------------------------------------------------
12
+ export { inlineLinkAtPosition } from "./markdown/links.js";
134
13
  /** Columns held back from the measured width for the scrollbar and right edge. */
135
14
  const MARKDOWN_SCROLLBAR_RESERVE = 2;
136
15
  export const MarkdownView = function MarkdownView({ content, blocks: providedBlocks, showLineNumbers = true, document, hScrollableBlocksRef, codeBlockRenderers, onLinkActivate, imageBasePath, }) {
@@ -138,8 +17,6 @@ export const MarkdownView = function MarkdownView({ content, blocks: providedBlo
138
17
  const palette = useGutterPalette();
139
18
  const { width: terminalWidth } = useTerminalDimensions();
140
19
  const blocks = useMemo(() => providedBlocks ?? flattenMarkdown(content), [providedBlocks, content]);
141
- // Blocks that must be told their width (diff fences) need the columns left
142
- // after the row-document gutter and the scrollbar.
143
20
  const contentWidth = Math.max(1, terminalWidth -
144
21
  computeRowDocumentGutterWidth({
145
22
  rowCount: blocks.length,
@@ -147,14 +24,12 @@ export const MarkdownView = function MarkdownView({ content, blocks: providedBlo
147
24
  signColumnWidth: DEFAULT_SIGN_COLUMN_WIDTH,
148
25
  }) -
149
26
  MARKDOWN_SCROLLBAR_RESERVE);
150
- // Merge user renderers over built-in defaults, normalizing keys to
151
- // lowercase so registration matches fence types case-insensitively.
152
27
  const mergedCodeBlockRenderers = useMemo(() => {
153
- const merged = { ...DEFAULT_CODE_BLOCK_RENDERERS };
28
+ const entries = new Map(Object.entries(DEFAULT_CODE_BLOCK_RENDERERS));
154
29
  for (const [key, renderer] of Object.entries(codeBlockRenderers ?? {})) {
155
- merged[key.trim().toLowerCase()] = renderer;
30
+ entries.set(key.trim().toLowerCase(), renderer);
156
31
  }
157
- return merged;
32
+ return Object.fromEntries(entries);
158
33
  }, [codeBlockRenderers]);
159
34
  const blockElements = useMemo(() => blocks.map((block, index) => (_jsx(FlatBlockRenderer, { block: block, blockIndex: index, theme: theme, syntax: syntax, contentWidth: contentWidth, hScrollableBlocksRef: hScrollableBlocksRef, codeBlockRenderers: mergedCodeBlockRenderers, onLinkActivate: onLinkActivate, imageBasePath: imageBasePath }, index))), [
160
35
  blocks,
@@ -168,338 +43,4 @@ export const MarkdownView = function MarkdownView({ content, blocks: providedBlo
168
43
  ]);
169
44
  return (_jsx("row-document", { ref: document?.ref, showLineNumbers: showLineNumbers, palette: palette, decorations: document?.decorations, signColumnWidth: DEFAULT_SIGN_COLUMN_WIDTH, style: { flexGrow: 1 }, onMouseDown: document?.onMouseDown, children: blockElements }));
170
45
  };
171
- // ---------------------------------------------------------------------------
172
- // Block renderer (flat)
173
- // ---------------------------------------------------------------------------
174
- const FlatBlockRenderer = function FlatBlockRenderer({ block, blockIndex, theme, syntax, contentWidth, hScrollableBlocksRef, codeBlockRenderers, onLinkActivate, imageBasePath, }) {
175
- const { token, indent, bullet } = block;
176
- // List item line (has bullet)
177
- if (bullet !== undefined) {
178
- // oxlint-disable-next-line no-use-before-define -- Deferred(lint-sweep): preserve deliberate top-down renderer organization
179
- return _jsx(ListLineRenderer, { block: block, theme: theme, onLinkActivate: onLinkActivate });
180
- }
181
- // Regular block token
182
- switch (token.type) {
183
- case "heading": {
184
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- Deferred(lint-sweep): marked token narrowing; schema-based validation in a later sweep
185
- const headingToken = token;
186
- return (_jsx(HeadingRenderer, { token: headingToken, theme: theme, indent: indent, onLinkActivate: onLinkActivate }));
187
- }
188
- case "paragraph": {
189
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- Deferred(lint-sweep): marked token narrowing; schema-based validation in a later sweep
190
- const paragraphToken = token;
191
- return (_jsx(ParagraphRenderer, { token: paragraphToken, theme: theme, indent: indent, onLinkActivate: onLinkActivate, imageBasePath: imageBasePath }));
192
- }
193
- case "code": {
194
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- Deferred(lint-sweep): marked token narrowing; schema-based validation in a later sweep
195
- const codeToken = token;
196
- return (_jsx(CodeBlock, { token: codeToken, blockIndex: blockIndex, theme: theme, syntax: syntax, indent: indent, contentWidth: contentWidth, hScrollableBlocksRef: hScrollableBlocksRef, renderers: codeBlockRenderers }));
197
- }
198
- case "blockquote": {
199
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- Deferred(lint-sweep): marked token narrowing; schema-based validation in a later sweep
200
- const blockquoteToken = token;
201
- return (_jsx(BlockquoteRenderer, { token: blockquoteToken, theme: theme, indent: indent, onLinkActivate: onLinkActivate }));
202
- }
203
- case "table": {
204
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- Deferred(lint-sweep): marked token narrowing; schema-based validation in a later sweep
205
- const tableToken = token;
206
- // oxlint-disable-next-line no-use-before-define -- Deferred(lint-sweep): preserve deliberate top-down renderer organization
207
- return _jsx(MarkdownTableRenderer, { token: tableToken, indent: indent });
208
- }
209
- case "hr": {
210
- // oxlint-disable-next-line no-use-before-define -- Deferred(lint-sweep): preserve deliberate top-down renderer organization
211
- return _jsx(HorizontalRule, { theme: theme, indent: indent });
212
- }
213
- case "space":
214
- case "html": {
215
- return null;
216
- }
217
- default: {
218
- if ("text" in token && typeof token.text === "string") {
219
- return (_jsx("text", { content: token.text, style: {
220
- fg: theme.markdownText,
221
- marginBottom: 1,
222
- marginLeft: 1 + indent,
223
- marginRight: 1,
224
- marginTop: 0,
225
- } }));
226
- }
227
- return null;
228
- }
229
- }
230
- };
231
- // ---------------------------------------------------------------------------
232
- // List line renderer
233
- // ---------------------------------------------------------------------------
234
- const ListLineRenderer = function ListLineRenderer({ block, theme, onLinkActivate, }) {
235
- const { token, indent, bullet, checked } = block;
236
- const checkboxPrefix = checkboxMarker(checked);
237
- // Get inline tokens from the text/paragraph token
238
- const inlineTokens = "tokens" in token && Array.isArray(token.tokens) ? token.tokens : [];
239
- const hasText = "text" in token && typeof token.text === "string" && token.text.length > 0;
240
- const hasContent = inlineTokens.length > 0 || hasText;
241
- let content = null;
242
- if (inlineTokens.length > 0) {
243
- // oxlint-disable-next-line no-use-before-define -- Deferred(lint-sweep): preserve deliberate top-down renderer organization
244
- content = _jsx(InlineTokens, { tokens: inlineTokens, theme: theme });
245
- }
246
- else if (hasText) {
247
- const tokenText = "text" in token ? token.text : "";
248
- content = typeof tokenText === "string" ? tokenText : "";
249
- }
250
- return (_jsx("box", { style: { marginLeft: 1 + indent, marginRight: 1 }, children: _jsxs("text", { style: { fg: theme.markdownText }, onMouseDown: linkMouseHandler(inlineTokens, onLinkActivate, Bun.stringWidth(`${bullet}${checkboxPrefix}`)), children: [_jsx("span", { fg: theme.markdownListItem, children: bullet }), checkboxPrefix !== "" && (_jsx("span", { fg: checked === true ? theme.accent : theme.textMuted, children: checkboxPrefix })), hasContent && content] }) }));
251
- };
252
- // ---------------------------------------------------------------------------
253
- // Block renderers
254
- // ---------------------------------------------------------------------------
255
- const HeadingRenderer = function HeadingRenderer({ token, theme, indent, onLinkActivate, }) {
256
- const headingColors = {
257
- 1: theme.markdownHeading,
258
- 2: theme.secondary,
259
- 3: theme.accent,
260
- 4: theme.text,
261
- 5: theme.textMuted,
262
- 6: theme.textMuted,
263
- };
264
- const prefixes = {
265
- 1: "# ",
266
- 2: "## ",
267
- 3: "### ",
268
- 4: "#### ",
269
- 5: "##### ",
270
- 6: "###### ",
271
- };
272
- return (_jsx("box", { style: { marginBottom: 1, marginLeft: indent, marginTop: 1 }, children: _jsxs("text", { style: { fg: headingColors[token.depth] || theme.text }, onMouseDown: linkMouseHandler(token.tokens, onLinkActivate, Bun.stringWidth(prefixes[token.depth] || "")), children: [_jsx("span", { fg: theme.textMuted, children: prefixes[token.depth] }), _jsx("strong", { children: _jsx(InlineTokens, { tokens: token.tokens, theme: theme }) })] }) }));
273
- };
274
- const ParagraphRenderer = function ParagraphRenderer({ token, theme, indent, onLinkActivate, imageBasePath, }) {
275
- const segments = splitMarkdownImages(token.tokens);
276
- return (_jsx("box", { style: {
277
- flexDirection: "column",
278
- marginBottom: 1,
279
- marginLeft: 1 + indent,
280
- marginRight: 1,
281
- }, children: segments.map((segment, index) => segment.type === "image" ? (_jsx(MarkdownImage, { image: segment, basePath: imageBasePath, theme: theme }, index)) : (_jsx("text", { style: { fg: theme.markdownText }, onMouseDown: linkMouseHandler(segment.tokens, onLinkActivate), children: _jsx(InlineTokens, { tokens: segment.tokens, theme: theme }) }, index))) }));
282
- };
283
- const MarkdownImage = function MarkdownImage({ image, basePath, theme, }) {
284
- const source = resolveMarkdownImageSource(image.source, basePath);
285
- const [state, setState] = useState("loading");
286
- useEffect(() => {
287
- setState("loading");
288
- }, [source]);
289
- return (_jsxs("box", { style: { flexDirection: "column" }, children: [state === "loading" && (_jsx("text", { content: `Loading image: ${image.alt ?? image.source}`, fg: theme.textMuted })), state === "error" && (_jsx("text", { content: `Image failed to load: ${image.alt ?? image.source}`, fg: theme.error })), _jsx("image", { source: source, fit: "fit", protocol: "auto", onLoad: () => {
290
- setState("loaded");
291
- }, onError: () => {
292
- setState("error");
293
- }, style: { height: image.height ?? 12, width: image.width ?? "100%" } })] }));
294
- };
295
- const BlockquoteRenderer = function BlockquoteRenderer({ token, theme, indent, onLinkActivate, }) {
296
- // Collect inline tokens from blockquote's child paragraphs/text
297
- const inlineTokens = [];
298
- for (const child of token.tokens) {
299
- if ("tokens" in child && Array.isArray(child.tokens)) {
300
- if (inlineTokens.length > 0) {
301
- inlineTokens.push({ raw: "\n", type: "br" });
302
- }
303
- inlineTokens.push(...child.tokens);
304
- }
305
- else if ("text" in child && typeof child.text === "string") {
306
- inlineTokens.push(child);
307
- }
308
- }
309
- return (_jsx("box", { border: ["left"], borderColor: theme.markdownBlockQuote, borderStyle: "single", style: {
310
- marginBottom: 1,
311
- marginLeft: 1 + indent,
312
- marginRight: 1,
313
- marginTop: 0,
314
- paddingLeft: 1,
315
- }, children: _jsx("text", { style: { fg: theme.textMuted }, onMouseDown: linkMouseHandler(inlineTokens, onLinkActivate), children: _jsx(InlineTokens, { tokens: inlineTokens, theme: theme }) }) }));
316
- };
317
- const MarkdownTableRenderer = function MarkdownTableRenderer({ token, indent, }) {
318
- const { theme } = useTheme();
319
- const content = useMemo(() => {
320
- const headerRow = token.header.map((cell) => {
321
- // oxlint-disable-next-line no-use-before-define -- Deferred(lint-sweep): preserve deliberate top-down renderer organization
322
- const chunks = inlineTokensToChunks(cell.tokens, theme);
323
- // Wrap header chunks in bold
324
- return chunks.length > 0
325
- ? chunks.map((c) => boldChunk(c))
326
- : [
327
- // oxlint-disable-next-line no-use-before-define -- Deferred(lint-sweep): preserve deliberate top-down renderer organization
328
- boldChunk(getPlainText(cell.tokens).trim()),
329
- ];
330
- });
331
- const dataRows = token.rows.map((row) => row.map((cell) => {
332
- // oxlint-disable-next-line no-use-before-define -- Deferred(lint-sweep): preserve deliberate top-down renderer organization
333
- const chunks = inlineTokensToChunks(cell.tokens, theme);
334
- return chunks.length > 0
335
- ? chunks
336
- : [
337
- // oxlint-disable-next-line no-use-before-define -- Deferred(lint-sweep): preserve deliberate top-down renderer organization
338
- { __isChunk: true, text: getPlainText(cell.tokens) },
339
- ];
340
- }));
341
- return [headerRow, ...dataRows];
342
- }, [token, theme]);
343
- return (_jsx("box", { style: { marginBottom: 1, marginLeft: 1 + indent, marginRight: 1 }, children: _jsx("text-table", { content: content, wrapMode: "word", columnWidthMode: "content", cellPadding: 0, border: true, borderStyle: "single", borderColor: theme.border, fg: theme.text }) }));
344
- };
345
- const HorizontalRule = function HorizontalRule({ theme, indent, }) {
346
- return (_jsx("box", { style: { marginBottom: 1, marginLeft: 1 + indent, marginRight: 1, marginTop: 0 }, children: _jsx("text", { style: { fg: theme.markdownHorizontalRule }, content: "─".repeat(40) }) }));
347
- };
348
- // ---------------------------------------------------------------------------
349
- // Inline token rendering (React elements)
350
- // ---------------------------------------------------------------------------
351
- const InlineTokens = function InlineTokens({ tokens, theme, }) {
352
- const result = [];
353
- for (let i = 0; i < tokens.length; i += 1) {
354
- const token = tokens[i];
355
- if (token === undefined) {
356
- continue;
357
- }
358
- const key = i;
359
- switch (token.type) {
360
- case "text": {
361
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- Deferred(lint-sweep): marked token narrowing; schema-based validation in a later sweep
362
- result.push(normalizeSoftLineEndings(token.text));
363
- break;
364
- }
365
- case "strong": {
366
- result.push(_jsx("strong", { children: _jsx(InlineTokens, { tokens: token.tokens, theme: theme }) }, key));
367
- break;
368
- }
369
- case "em": {
370
- result.push(_jsx("em", { children: _jsx(InlineTokens, { tokens: token.tokens, theme: theme }) }, key));
371
- break;
372
- }
373
- case "codespan": {
374
- result.push(_jsx("span", { fg: theme.markdownCode, bg: theme.backgroundPanel, children: ` ${token.text} ` }, key));
375
- break;
376
- }
377
- case "link": {
378
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- Deferred(lint-sweep): marked token narrowing; schema-based validation in a later sweep
379
- const linkToken = token;
380
- result.push(_jsx("u", { children: _jsx("a", { href: linkToken.href, fg: theme.markdownLink, children: _jsx(InlineTokens, { tokens: linkToken.tokens, theme: theme }) }) }, key));
381
- break;
382
- }
383
- case "del": {
384
- result.push(_jsxs("span", { fg: theme.textMuted, children: ["~", _jsx(InlineTokens, { tokens: token.tokens, theme: theme }), "~"] }, key));
385
- break;
386
- }
387
- case "image": {
388
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- Deferred(lint-sweep): marked token narrowing; schema-based validation in a later sweep
389
- const imgToken = token;
390
- result.push(_jsx("span", { fg: theme.textMuted, children: imgToken.text || imgToken.href }, key));
391
- break;
392
- }
393
- case "br": {
394
- result.push("\n");
395
- break;
396
- }
397
- case "escape": {
398
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- Deferred(lint-sweep): marked token narrowing; schema-based validation in a later sweep
399
- result.push(token.text);
400
- break;
401
- }
402
- case "space": {
403
- result.push(" ");
404
- break;
405
- }
406
- default: {
407
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- Deferred(lint-sweep): marked token narrowing; schema-based validation in a later sweep
408
- if ("text" in token && typeof token.text === "string") {
409
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- Deferred(lint-sweep): marked token narrowing; schema-based validation in a later sweep
410
- result.push(token.text);
411
- }
412
- break;
413
- }
414
- }
415
- }
416
- return result;
417
- };
418
- // ---------------------------------------------------------------------------
419
- // Inline token rendering (TextChunks — for text-table cells)
420
- // ---------------------------------------------------------------------------
421
- const inlineTokensToChunks = function inlineTokensToChunks(tokens, theme) {
422
- const chunks = [];
423
- for (const token of tokens) {
424
- switch (token.type) {
425
- case "text": {
426
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- Deferred(lint-sweep): marked token narrowing; schema-based validation in a later sweep
427
- chunks.push({ __isChunk: true, text: token.text });
428
- break;
429
- }
430
- case "strong": {
431
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- Deferred(lint-sweep): marked token narrowing; schema-based validation in a later sweep
432
- for (const sub of inlineTokensToChunks(token.tokens, theme)) {
433
- chunks.push(boldChunk(sub));
434
- }
435
- break;
436
- }
437
- case "em": {
438
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- Deferred(lint-sweep): marked token narrowing; schema-based validation in a later sweep
439
- for (const sub of inlineTokensToChunks(token.tokens, theme)) {
440
- chunks.push(italicChunk(sub));
441
- }
442
- break;
443
- }
444
- case "codespan": {
445
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- Deferred(lint-sweep): marked token narrowing; schema-based validation in a later sweep
446
- const codespanToken = token;
447
- chunks.push({
448
- __isChunk: true,
449
- bg: parseColor(theme.backgroundPanel),
450
- fg: parseColor(theme.markdownCode),
451
- text: ` ${codespanToken.text} `,
452
- });
453
- break;
454
- }
455
- case "link": {
456
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- Deferred(lint-sweep): marked token narrowing; schema-based validation in a later sweep
457
- const linkToken = token;
458
- for (const sub of inlineTokensToChunks(linkToken.tokens, theme)) {
459
- chunks.push(underlineChunk({ ...sub, fg: parseColor(theme.markdownLink) }));
460
- }
461
- break;
462
- }
463
- case "escape": {
464
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- Deferred(lint-sweep): marked token narrowing; schema-based validation in a later sweep
465
- chunks.push({ __isChunk: true, text: token.text });
466
- break;
467
- }
468
- default: {
469
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- Deferred(lint-sweep): marked token narrowing; schema-based validation in a later sweep
470
- if ("text" in token && typeof token.text === "string") {
471
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- Deferred(lint-sweep): marked token narrowing; schema-based validation in a later sweep
472
- chunks.push({ __isChunk: true, text: token.text });
473
- }
474
- break;
475
- }
476
- }
477
- }
478
- return chunks;
479
- };
480
- // ---------------------------------------------------------------------------
481
- // Plain text extraction (only for width computation, not rendering)
482
- // ---------------------------------------------------------------------------
483
- const getPlainText = function getPlainText(tokens) {
484
- return tokens
485
- .map((token) => {
486
- if (token.type === "text") {
487
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- Deferred(lint-sweep): marked token narrowing; schema-based validation in a later sweep
488
- return token.text;
489
- }
490
- if (token.type === "codespan") {
491
- // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- Deferred(lint-sweep): marked token narrowing; schema-based validation in a later sweep
492
- return token.text;
493
- }
494
- if ("tokens" in token && token.tokens) {
495
- return getPlainText(token.tokens);
496
- }
497
- if ("text" in token) {
498
- const tokenText = token.text;
499
- return typeof tokenText === "string" ? tokenText : "";
500
- }
501
- return "";
502
- })
503
- .join("");
504
- };
505
46
  //# sourceMappingURL=markdown-view.js.map