@tooee/renderers 0.11.0 → 0.13.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/dist/chooser/choose-filter.d.ts.map +1 -1
- package/dist/chooser/choose-filter.js.map +1 -1
- package/dist/chooser/choose-highlighted-text.d.ts.map +1 -1
- package/dist/chooser/choose-highlighted-text.js.map +1 -1
- package/dist/chooser/choose-list.d.ts.map +1 -1
- package/dist/chooser/choose-list.js.map +1 -1
- package/dist/chooser/choose-store.d.ts +3 -3
- package/dist/chooser/choose-store.d.ts.map +1 -1
- package/dist/chooser/choose-store.js.map +1 -1
- package/dist/chooser/chooser.d.ts.map +1 -1
- package/dist/chooser/chooser.js.map +1 -1
- package/dist/chooser/source.d.ts.map +1 -1
- package/dist/chooser/source.js.map +1 -1
- package/dist/chooser/use-choose.d.ts.map +1 -1
- package/dist/chooser/use-choose.js.map +1 -1
- package/dist/code-blocks.d.ts.map +1 -1
- package/dist/code-blocks.js.map +1 -1
- package/dist/command-palette.d.ts.map +1 -1
- package/dist/command-palette.js.map +1 -1
- package/dist/context-menu.d.ts.map +1 -1
- package/dist/context-menu.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/markdown/blocks/blockquote.d.ts.map +1 -1
- package/dist/markdown/blocks/blockquote.js.map +1 -1
- package/dist/markdown/blocks/flat-block.d.ts.map +1 -1
- package/dist/markdown/blocks/flat-block.js.map +1 -1
- package/dist/markdown/blocks/heading.d.ts.map +1 -1
- package/dist/markdown/blocks/heading.js.map +1 -1
- package/dist/markdown/blocks/list-line.d.ts.map +1 -1
- package/dist/markdown/blocks/list-line.js.map +1 -1
- package/dist/markdown/blocks/paragraph.d.ts.map +1 -1
- package/dist/markdown/blocks/paragraph.js.map +1 -1
- package/dist/markdown/blocks/table.d.ts.map +1 -1
- package/dist/markdown/blocks/table.js.map +1 -1
- package/dist/markdown/links.d.ts.map +1 -1
- package/dist/markdown/links.js.map +1 -1
- package/dist/markdown/plain-text.d.ts +1 -1
- package/dist/markdown/plain-text.d.ts.map +1 -1
- package/dist/markdown/plain-text.js +1 -1
- package/dist/markdown/plain-text.js.map +1 -1
- package/dist/markdown/table-links.d.ts.map +1 -1
- package/dist/markdown/table-links.js.map +1 -1
- package/dist/markdown/tokens.d.ts.map +1 -1
- package/dist/markdown/tokens.js.map +1 -1
- package/dist/markdown/visit-inline.d.ts.map +1 -1
- package/dist/markdown/visit-inline.js.map +1 -1
- package/dist/markdown-blocks.d.ts.map +1 -1
- package/dist/markdown-blocks.js.map +1 -1
- package/dist/markdown-images.d.ts.map +1 -1
- package/dist/markdown-images.js.map +1 -1
- package/dist/markdown-view.d.ts +6 -1
- package/dist/markdown-view.d.ts.map +1 -1
- package/dist/markdown-view.js +2 -2
- package/dist/markdown-view.js.map +1 -1
- package/dist/mermaid.d.ts.map +1 -1
- package/dist/mermaid.js +8 -4
- package/dist/mermaid.js.map +1 -1
- package/dist/parsers.d.ts.map +1 -1
- package/dist/parsers.js.map +1 -1
- package/dist/row-document-renderable.d.ts +11 -1
- package/dist/row-document-renderable.d.ts.map +1 -1
- package/dist/row-document-renderable.js +16 -7
- package/dist/row-document-renderable.js.map +1 -1
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js.map +1 -1
- package/dist/table.d.ts.map +1 -1
- package/dist/table.js.map +1 -1
- package/dist/text-table-internals.d.ts.map +1 -1
- package/dist/text-table-internals.js.map +1 -1
- package/package.json +6 -6
- package/src/chooser/choose-filter.tsx +1 -0
- package/src/chooser/choose-highlighted-text.tsx +2 -0
- package/src/chooser/choose-list.tsx +6 -0
- package/src/chooser/choose-store.ts +20 -3
- package/src/chooser/chooser.tsx +2 -0
- package/src/chooser/source.ts +5 -0
- package/src/chooser/use-choose.ts +44 -0
- package/src/code-blocks.tsx +14 -0
- package/src/command-palette.tsx +4 -0
- package/src/context-menu.tsx +13 -0
- package/src/index.ts +44 -0
- package/src/markdown/blocks/blockquote.tsx +2 -0
- package/src/markdown/blocks/flat-block.tsx +13 -0
- package/src/markdown/blocks/heading.tsx +1 -0
- package/src/markdown/blocks/list-line.tsx +3 -0
- package/src/markdown/blocks/paragraph.tsx +1 -0
- package/src/markdown/blocks/table.tsx +7 -0
- package/src/markdown/links.ts +26 -0
- package/src/markdown/plain-text.ts +6 -1
- package/src/markdown/table-links.ts +12 -0
- package/src/markdown/tokens.ts +2 -0
- package/src/markdown/visit-inline.ts +20 -0
- package/src/markdown-blocks.ts +31 -0
- package/src/markdown-images.ts +21 -0
- package/src/markdown-view.tsx +11 -1
- package/src/mermaid.ts +21 -4
- package/src/parsers.ts +39 -0
- package/src/row-document-renderable.ts +72 -7
- package/src/source.ts +18 -0
- package/src/table.tsx +32 -0
- package/src/text-table-internals.ts +12 -0
package/src/index.ts
CHANGED
|
@@ -1,14 +1,23 @@
|
|
|
1
1
|
export { MarkdownView } from "./markdown-view.js";
|
|
2
|
+
|
|
2
3
|
export type { MarkdownLinkHandler } from "./markdown-view.js";
|
|
4
|
+
|
|
3
5
|
export { flattenMarkdown, getFlatBlockText } from "./markdown-blocks.js";
|
|
6
|
+
|
|
7
|
+
export { getPlainText } from "./markdown/plain-text.js";
|
|
8
|
+
|
|
4
9
|
export type { FlatBlock, FlattenMarkdownOptions } from "./markdown-blocks.js";
|
|
10
|
+
|
|
5
11
|
export {
|
|
6
12
|
parseObsidianImageEmbed,
|
|
7
13
|
resolveMarkdownImageSource,
|
|
8
14
|
splitMarkdownImages,
|
|
9
15
|
} from "./markdown-images.js";
|
|
16
|
+
|
|
10
17
|
export type { MarkdownImageEmbed, MarkdownInlineSegment } from "./markdown-images.js";
|
|
18
|
+
|
|
11
19
|
export { sourceLines, sourceLineAdapter, SourceIndex } from "./source.js";
|
|
20
|
+
|
|
12
21
|
export type {
|
|
13
22
|
DocumentRowAnchor,
|
|
14
23
|
DocumentRowSource,
|
|
@@ -16,6 +25,7 @@ export type {
|
|
|
16
25
|
SourcePoint,
|
|
17
26
|
SourceSpan,
|
|
18
27
|
} from "./source.js";
|
|
28
|
+
|
|
19
29
|
export {
|
|
20
30
|
CodeBlockChrome,
|
|
21
31
|
defaultCodeBlockRenderer,
|
|
@@ -23,21 +33,37 @@ export {
|
|
|
23
33
|
DEFAULT_CODE_BLOCK_RENDERERS,
|
|
24
34
|
getFenceType,
|
|
25
35
|
} from "./code-blocks.js";
|
|
36
|
+
|
|
26
37
|
export type { CodeBlockRenderer, CodeBlockRendererProps, CodeBlockHScroll } from "./code-blocks.js";
|
|
38
|
+
|
|
27
39
|
export { CodeView } from "./code-view.js";
|
|
40
|
+
|
|
28
41
|
export { Table, computeColumnWidths, formatTableCell, isNumeric, sampleRows } from "./table.js";
|
|
42
|
+
|
|
29
43
|
export type { TableProps, ColumnWidthOptions } from "./table.js";
|
|
44
|
+
|
|
30
45
|
export type { ColumnDef, TableRow } from "./table-types.js";
|
|
46
|
+
|
|
31
47
|
export { CommandPalette } from "./command-palette.js";
|
|
48
|
+
|
|
32
49
|
export type { CommandPaletteEntry } from "./command-palette.js";
|
|
50
|
+
|
|
33
51
|
export { Chooser } from "./chooser/chooser.js";
|
|
52
|
+
|
|
34
53
|
export type { ChooserProps } from "./chooser/chooser.js";
|
|
54
|
+
|
|
35
55
|
export { ChooseFilter } from "./chooser/choose-filter.js";
|
|
56
|
+
|
|
36
57
|
export type { ChooseFilterProps } from "./chooser/choose-filter.js";
|
|
58
|
+
|
|
37
59
|
export { ChooseHighlightedText } from "./chooser/choose-highlighted-text.js";
|
|
60
|
+
|
|
38
61
|
export type { ChooseHighlightedTextProps } from "./chooser/choose-highlighted-text.js";
|
|
62
|
+
|
|
39
63
|
export { ChooseList } from "./chooser/choose-list.js";
|
|
64
|
+
|
|
40
65
|
export type { ChooseItemRenderContext, ChooseListProps } from "./chooser/choose-list.js";
|
|
66
|
+
|
|
41
67
|
export {
|
|
42
68
|
createChooseStore,
|
|
43
69
|
selectActiveIndex,
|
|
@@ -49,11 +75,17 @@ export {
|
|
|
49
75
|
selectReloadRevision,
|
|
50
76
|
selectSelectedOriginalIndices,
|
|
51
77
|
} from "./chooser/choose-store.js";
|
|
78
|
+
|
|
52
79
|
export type { ChooseStore, ChooseStoreContext, ChooseStoreEvents } from "./chooser/choose-store.js";
|
|
80
|
+
|
|
53
81
|
export { fuzzyFilter } from "./chooser/fuzzy.js";
|
|
82
|
+
|
|
54
83
|
export type { FuzzyMatch } from "./chooser/fuzzy.js";
|
|
84
|
+
|
|
55
85
|
export { loadChooseSource } from "./chooser/source.js";
|
|
86
|
+
|
|
56
87
|
export { useChoose } from "./chooser/use-choose.js";
|
|
88
|
+
|
|
57
89
|
export type {
|
|
58
90
|
ChooseCommandGroup,
|
|
59
91
|
ChooseController,
|
|
@@ -62,6 +94,7 @@ export type {
|
|
|
62
94
|
UseChooseOptions,
|
|
63
95
|
UseChooseResult,
|
|
64
96
|
} from "./chooser/use-choose.js";
|
|
97
|
+
|
|
65
98
|
export type {
|
|
66
99
|
ChooseContentProvider,
|
|
67
100
|
ChooseItem,
|
|
@@ -69,20 +102,31 @@ export type {
|
|
|
69
102
|
ChooseResult,
|
|
70
103
|
ChooseSource,
|
|
71
104
|
} from "./chooser/types.js";
|
|
105
|
+
|
|
72
106
|
export { ContextMenu } from "./context-menu.js";
|
|
107
|
+
|
|
73
108
|
export type { ContextMenuEntry } from "./context-menu.js";
|
|
109
|
+
|
|
74
110
|
export { parseCSV, parseTSV, parseJSON, parseAuto, detectFormat } from "./parsers.js";
|
|
111
|
+
|
|
75
112
|
export type { Format, ParsedTable, TableData } from "./parsers.js";
|
|
113
|
+
|
|
76
114
|
export { RowDocumentRenderable } from "./row-document-renderable.js";
|
|
115
|
+
|
|
77
116
|
export {
|
|
78
117
|
DEFAULT_SIGN_COLUMN_WIDTH,
|
|
79
118
|
computeRowDocumentGutterWidth,
|
|
80
119
|
} from "./row-document-renderable.js";
|
|
120
|
+
|
|
81
121
|
export type {
|
|
82
122
|
RowDocumentOptions,
|
|
83
123
|
RowDocumentPalette,
|
|
124
|
+
RowScrollAlign,
|
|
84
125
|
VisibleRowRange,
|
|
85
126
|
} from "./row-document-renderable.js";
|
|
127
|
+
|
|
86
128
|
export type { DecorationLayer, RowDecoration } from "./decoration-layer.js";
|
|
129
|
+
|
|
87
130
|
export type { DocumentBindings } from "./document-bindings.js";
|
|
131
|
+
|
|
88
132
|
export { useGutterPalette } from "./use-gutter-palette.js";
|
|
@@ -19,11 +19,13 @@ export const BlockquoteRenderer = function BlockquoteRenderer({
|
|
|
19
19
|
onLinkActivate?: MarkdownLinkHandler;
|
|
20
20
|
}): ReactNode {
|
|
21
21
|
const inlineTokens: Token[] = [];
|
|
22
|
+
|
|
22
23
|
for (const child of token.tokens) {
|
|
23
24
|
if ("tokens" in child && Array.isArray(child.tokens)) {
|
|
24
25
|
if (inlineTokens.length > 0) {
|
|
25
26
|
inlineTokens.push({ raw: "\n", type: "br" });
|
|
26
27
|
}
|
|
28
|
+
|
|
27
29
|
inlineTokens.push(...child.tokens);
|
|
28
30
|
} else if (hasMarkedText(child)) {
|
|
29
31
|
inlineTokens.push(child);
|
|
@@ -47,6 +47,7 @@ export const FlatBlockRenderer = function FlatBlockRenderer({
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
const heading = narrowToken(token, "heading");
|
|
50
|
+
|
|
50
51
|
if (heading !== null) {
|
|
51
52
|
return (
|
|
52
53
|
<HeadingRenderer
|
|
@@ -58,7 +59,9 @@ export const FlatBlockRenderer = function FlatBlockRenderer({
|
|
|
58
59
|
/>
|
|
59
60
|
);
|
|
60
61
|
}
|
|
62
|
+
|
|
61
63
|
const paragraph = narrowToken(token, "paragraph");
|
|
64
|
+
|
|
62
65
|
if (paragraph !== null) {
|
|
63
66
|
return (
|
|
64
67
|
<ParagraphRenderer
|
|
@@ -70,7 +73,9 @@ export const FlatBlockRenderer = function FlatBlockRenderer({
|
|
|
70
73
|
/>
|
|
71
74
|
);
|
|
72
75
|
}
|
|
76
|
+
|
|
73
77
|
const code = narrowToken(token, "code");
|
|
78
|
+
|
|
74
79
|
if (code !== null) {
|
|
75
80
|
return (
|
|
76
81
|
<CodeBlock
|
|
@@ -85,7 +90,9 @@ export const FlatBlockRenderer = function FlatBlockRenderer({
|
|
|
85
90
|
/>
|
|
86
91
|
);
|
|
87
92
|
}
|
|
93
|
+
|
|
88
94
|
const blockquote = narrowToken(token, "blockquote");
|
|
95
|
+
|
|
89
96
|
if (blockquote !== null) {
|
|
90
97
|
return (
|
|
91
98
|
<BlockquoteRenderer
|
|
@@ -96,19 +103,25 @@ export const FlatBlockRenderer = function FlatBlockRenderer({
|
|
|
96
103
|
/>
|
|
97
104
|
);
|
|
98
105
|
}
|
|
106
|
+
|
|
99
107
|
const table = narrowToken(token, "table");
|
|
108
|
+
|
|
100
109
|
if (table !== null) {
|
|
101
110
|
return <MarkdownTableRenderer token={table} indent={indent} onLinkActivate={onLinkActivate} />;
|
|
102
111
|
}
|
|
112
|
+
|
|
103
113
|
if (token.type === "hr") {
|
|
104
114
|
return <HorizontalRule theme={theme} indent={indent} />;
|
|
105
115
|
}
|
|
116
|
+
|
|
106
117
|
if (token.type === "space" || token.type === "html") {
|
|
107
118
|
return null;
|
|
108
119
|
}
|
|
120
|
+
|
|
109
121
|
if (!hasMarkedText(token)) {
|
|
110
122
|
return null;
|
|
111
123
|
}
|
|
124
|
+
|
|
112
125
|
return (
|
|
113
126
|
<text
|
|
114
127
|
content={token.text}
|
|
@@ -20,12 +20,15 @@ export const ListLineRenderer = function ListLineRenderer({
|
|
|
20
20
|
}): ReactNode {
|
|
21
21
|
const { token, indent, bullet, checked } = block;
|
|
22
22
|
const checkboxPrefix = checkboxMarker(checked);
|
|
23
|
+
|
|
23
24
|
const inlineTokens: Token[] =
|
|
24
25
|
"tokens" in token && Array.isArray(token.tokens) ? token.tokens : [];
|
|
26
|
+
|
|
25
27
|
const tokenText = hasMarkedText(token) ? token.text : "";
|
|
26
28
|
const hasContent = inlineTokens.length > 0 || tokenText.length > 0;
|
|
27
29
|
|
|
28
30
|
let content: ReactNode = null;
|
|
31
|
+
|
|
29
32
|
if (inlineTokens.length > 0) {
|
|
30
33
|
content = <InlineTokens tokens={inlineTokens} theme={theme} />;
|
|
31
34
|
} else if (tokenText.length > 0) {
|
|
@@ -24,24 +24,31 @@ export const MarkdownTableRenderer = function MarkdownTableRenderer({
|
|
|
24
24
|
const content: TextTableContent = useMemo(() => {
|
|
25
25
|
const headerRow: TextTableCellContent[] = token.header.map((cell) => {
|
|
26
26
|
const chunks = inlineTokensToChunks(cell.tokens, theme);
|
|
27
|
+
|
|
27
28
|
return chunks.length > 0
|
|
28
29
|
? chunks.map((item) => boldChunk(item))
|
|
29
30
|
: [boldChunk(getPlainText(cell.tokens).trim())];
|
|
30
31
|
});
|
|
32
|
+
|
|
31
33
|
const dataRows = token.rows.map((row) =>
|
|
32
34
|
row.map((cell) => {
|
|
33
35
|
const chunks = inlineTokensToChunks(cell.tokens, theme);
|
|
36
|
+
|
|
34
37
|
if (chunks.length > 0) {
|
|
35
38
|
return chunks;
|
|
36
39
|
}
|
|
40
|
+
|
|
37
41
|
const fallbackCell: TextTableCellContent = [
|
|
38
42
|
{ __isChunk: true, text: getPlainText(cell.tokens) },
|
|
39
43
|
];
|
|
44
|
+
|
|
40
45
|
return fallbackCell;
|
|
41
46
|
})
|
|
42
47
|
);
|
|
48
|
+
|
|
43
49
|
return [headerRow, ...dataRows];
|
|
44
50
|
}, [token, theme]);
|
|
51
|
+
|
|
45
52
|
const onMouseDown = useMemo(
|
|
46
53
|
() => tableLinkMouseHandler(content, onLinkActivate),
|
|
47
54
|
[content, onLinkActivate]
|
package/src/markdown/links.ts
CHANGED
|
@@ -23,8 +23,10 @@ export const inlineLinkAtPosition = function inlineLinkAtPosition(
|
|
|
23
23
|
|
|
24
24
|
const advanceText = (value: string, href?: string): void => {
|
|
25
25
|
const parts = value.split("\n");
|
|
26
|
+
|
|
26
27
|
for (const [index, part] of parts.entries()) {
|
|
27
28
|
const width = Bun.stringWidth(part);
|
|
29
|
+
|
|
28
30
|
if (
|
|
29
31
|
href !== undefined &&
|
|
30
32
|
line === position.line &&
|
|
@@ -33,7 +35,9 @@ export const inlineLinkAtPosition = function inlineLinkAtPosition(
|
|
|
33
35
|
) {
|
|
34
36
|
found = href;
|
|
35
37
|
}
|
|
38
|
+
|
|
36
39
|
column += width;
|
|
40
|
+
|
|
37
41
|
if (index < parts.length - 1) {
|
|
38
42
|
line += 1;
|
|
39
43
|
column = 0;
|
|
@@ -46,38 +50,51 @@ export const inlineLinkAtPosition = function inlineLinkAtPosition(
|
|
|
46
50
|
if (found !== null) {
|
|
47
51
|
return;
|
|
48
52
|
}
|
|
53
|
+
|
|
49
54
|
const text = narrowToken(token, "text");
|
|
55
|
+
|
|
50
56
|
if (text !== null) {
|
|
51
57
|
advanceText(normalizeSoftLineEndings(text.text), href);
|
|
52
58
|
continue;
|
|
53
59
|
}
|
|
60
|
+
|
|
54
61
|
const link = narrowToken(token, "link");
|
|
62
|
+
|
|
55
63
|
if (link !== null) {
|
|
56
64
|
visit(link.tokens, link.href);
|
|
57
65
|
continue;
|
|
58
66
|
}
|
|
67
|
+
|
|
59
68
|
const strong = narrowToken(token, "strong");
|
|
69
|
+
|
|
60
70
|
if (strong !== null) {
|
|
61
71
|
visit(strong.tokens, href);
|
|
62
72
|
continue;
|
|
63
73
|
}
|
|
74
|
+
|
|
64
75
|
const em = narrowToken(token, "em");
|
|
76
|
+
|
|
65
77
|
if (em !== null) {
|
|
66
78
|
visit(em.tokens, href);
|
|
67
79
|
continue;
|
|
68
80
|
}
|
|
81
|
+
|
|
69
82
|
const del = narrowToken(token, "del");
|
|
83
|
+
|
|
70
84
|
if (del !== null) {
|
|
71
85
|
advanceText("~", href);
|
|
72
86
|
visit(del.tokens, href);
|
|
73
87
|
advanceText("~", href);
|
|
74
88
|
continue;
|
|
75
89
|
}
|
|
90
|
+
|
|
76
91
|
const codespan = narrowToken(token, "codespan");
|
|
92
|
+
|
|
77
93
|
if (codespan !== null) {
|
|
78
94
|
advanceText(` ${codespan.text} `, href);
|
|
79
95
|
continue;
|
|
80
96
|
}
|
|
97
|
+
|
|
81
98
|
if (narrowToken(token, "br") !== null) {
|
|
82
99
|
advanceText("\n", href);
|
|
83
100
|
} else if (narrowToken(token, "space") !== null) {
|
|
@@ -89,6 +106,7 @@ export const inlineLinkAtPosition = function inlineLinkAtPosition(
|
|
|
89
106
|
};
|
|
90
107
|
|
|
91
108
|
visit(tokens);
|
|
109
|
+
|
|
92
110
|
return found;
|
|
93
111
|
};
|
|
94
112
|
|
|
@@ -100,23 +118,29 @@ export const linkMouseHandler = function linkMouseHandler(
|
|
|
100
118
|
if (onLinkActivate === undefined) {
|
|
101
119
|
return undefined;
|
|
102
120
|
}
|
|
121
|
+
|
|
103
122
|
return (event: MouseEvent): void => {
|
|
104
123
|
if (event.button !== 0) {
|
|
105
124
|
return;
|
|
106
125
|
}
|
|
126
|
+
|
|
107
127
|
const { target } = event;
|
|
128
|
+
|
|
108
129
|
if (target === null || target === undefined || !("lineInfo" in target)) {
|
|
109
130
|
return;
|
|
110
131
|
}
|
|
132
|
+
|
|
111
133
|
// SAFETY: OpenTUI supplies a renderable target, and the lineInfo guard proves this text-buffer member.
|
|
112
134
|
// oxlint-disable-next-line typescript/no-unsafe-type-assertion -- OpenTUI supplies renderable mouse targets
|
|
113
135
|
const text = target as TextBufferRenderable;
|
|
114
136
|
const visualLine = event.y - text.y;
|
|
115
137
|
const sourceLine = text.lineInfo.lineSources[visualLine];
|
|
116
138
|
const startColumn = text.lineInfo.lineStartCols[visualLine];
|
|
139
|
+
|
|
117
140
|
if (sourceLine === undefined || startColumn === undefined) {
|
|
118
141
|
return;
|
|
119
142
|
}
|
|
143
|
+
|
|
120
144
|
const href = inlineLinkAtPosition(
|
|
121
145
|
tokens,
|
|
122
146
|
{
|
|
@@ -125,9 +149,11 @@ export const linkMouseHandler = function linkMouseHandler(
|
|
|
125
149
|
},
|
|
126
150
|
initialColumn
|
|
127
151
|
);
|
|
152
|
+
|
|
128
153
|
if (href === null || onLinkActivate(href) !== true) {
|
|
129
154
|
return;
|
|
130
155
|
}
|
|
156
|
+
|
|
131
157
|
event.preventDefault();
|
|
132
158
|
event.stopPropagation();
|
|
133
159
|
};
|
|
@@ -2,21 +2,26 @@ import type { Token } from "marked";
|
|
|
2
2
|
|
|
3
3
|
import { hasMarkedText, narrowToken } from "./tokens.js";
|
|
4
4
|
|
|
5
|
-
/** Extract unstyled inline text for table-cell
|
|
5
|
+
/** Extract unstyled inline text, for table-cell fallbacks and heading outlines. */
|
|
6
6
|
export const getPlainText = function getPlainText(tokens: readonly Token[]): string {
|
|
7
7
|
return tokens
|
|
8
8
|
.map((token) => {
|
|
9
9
|
const text = narrowToken(token, "text");
|
|
10
|
+
|
|
10
11
|
if (text !== null) {
|
|
11
12
|
return text.text;
|
|
12
13
|
}
|
|
14
|
+
|
|
13
15
|
const codespan = narrowToken(token, "codespan");
|
|
16
|
+
|
|
14
17
|
if (codespan !== null) {
|
|
15
18
|
return codespan.text;
|
|
16
19
|
}
|
|
20
|
+
|
|
17
21
|
if ("tokens" in token && Array.isArray(token.tokens)) {
|
|
18
22
|
return getPlainText(token.tokens);
|
|
19
23
|
}
|
|
24
|
+
|
|
20
25
|
return hasMarkedText(token) ? token.text : "";
|
|
21
26
|
})
|
|
22
27
|
.join("");
|
|
@@ -11,20 +11,26 @@ export const chunkLinkAt = function chunkLinkAt(
|
|
|
11
11
|
): string | null {
|
|
12
12
|
let currentLine = 0;
|
|
13
13
|
let column = 0;
|
|
14
|
+
|
|
14
15
|
for (const chunk of chunks) {
|
|
15
16
|
const parts = chunk.text.split("\n");
|
|
17
|
+
|
|
16
18
|
for (const [index, part] of parts.entries()) {
|
|
17
19
|
const width = Bun.stringWidth(part);
|
|
20
|
+
|
|
18
21
|
if (currentLine === line && offset >= column && offset < column + width) {
|
|
19
22
|
return chunk.link?.url ?? null;
|
|
20
23
|
}
|
|
24
|
+
|
|
21
25
|
column += width;
|
|
26
|
+
|
|
22
27
|
if (index < parts.length - 1) {
|
|
23
28
|
currentLine += 1;
|
|
24
29
|
column = 0;
|
|
25
30
|
}
|
|
26
31
|
}
|
|
27
32
|
}
|
|
33
|
+
|
|
28
34
|
return null;
|
|
29
35
|
};
|
|
30
36
|
|
|
@@ -39,19 +45,25 @@ export const tableLinkMouseHandler = function tableLinkMouseHandler(
|
|
|
39
45
|
if (onLinkActivate === undefined) {
|
|
40
46
|
return undefined;
|
|
41
47
|
}
|
|
48
|
+
|
|
42
49
|
return (event: MouseEvent): void => {
|
|
43
50
|
if (event.button !== 0 || event.target === null) {
|
|
44
51
|
return;
|
|
45
52
|
}
|
|
53
|
+
|
|
46
54
|
const hit = textTableCellAt(event.target, event.x, event.y);
|
|
47
55
|
const chunks = hit === null ? null : content[hit.row]?.[hit.column];
|
|
56
|
+
|
|
48
57
|
if (hit === null || chunks === null || chunks === undefined) {
|
|
49
58
|
return;
|
|
50
59
|
}
|
|
60
|
+
|
|
51
61
|
const href = chunkLinkAt(chunks, hit.line, hit.offset);
|
|
62
|
+
|
|
52
63
|
if (href === null || onLinkActivate(href) !== true) {
|
|
53
64
|
return;
|
|
54
65
|
}
|
|
66
|
+
|
|
55
67
|
event.preventDefault();
|
|
56
68
|
event.stopPropagation();
|
|
57
69
|
};
|
package/src/markdown/tokens.ts
CHANGED
|
@@ -33,6 +33,7 @@ export const narrowToken = function narrowToken<Type extends keyof KnownTokenByT
|
|
|
33
33
|
if (token.type !== type) {
|
|
34
34
|
return null;
|
|
35
35
|
}
|
|
36
|
+
|
|
36
37
|
// SAFETY: Marked creates the token member selected by the checked type discriminator.
|
|
37
38
|
// oxlint-disable-next-line typescript/no-unsafe-type-assertion -- the Generic fallback prevents discriminator narrowing
|
|
38
39
|
return token as KnownTokenByType[Type];
|
|
@@ -43,6 +44,7 @@ export const hasMarkedText = function hasMarkedText(token: Token): token is Toke
|
|
|
43
44
|
if (!("text" in token)) {
|
|
44
45
|
return false;
|
|
45
46
|
}
|
|
47
|
+
|
|
46
48
|
// oxlint-disable-next-line anti-slop/no-runtime-typeof -- primitive check stays at the Marked token boundary
|
|
47
49
|
return typeof token.text === "string";
|
|
48
50
|
};
|
|
@@ -27,55 +27,75 @@ export const visitInline = function visitInline<Result>(
|
|
|
27
27
|
for (const [index, token] of tokens.entries()) {
|
|
28
28
|
const key = `${keyPrefix}${index}`;
|
|
29
29
|
const text = narrowToken(token, "text");
|
|
30
|
+
|
|
30
31
|
if (text !== null) {
|
|
31
32
|
result.push(...sink.text(text, key));
|
|
32
33
|
continue;
|
|
33
34
|
}
|
|
35
|
+
|
|
34
36
|
const strong = narrowToken(token, "strong");
|
|
37
|
+
|
|
35
38
|
if (strong !== null) {
|
|
36
39
|
result.push(...sink.strong(strong, visitInline(strong.tokens, sink, `${key}.`), key));
|
|
37
40
|
continue;
|
|
38
41
|
}
|
|
42
|
+
|
|
39
43
|
const em = narrowToken(token, "em");
|
|
44
|
+
|
|
40
45
|
if (em !== null) {
|
|
41
46
|
result.push(...sink.em(em, visitInline(em.tokens, sink, `${key}.`), key));
|
|
42
47
|
continue;
|
|
43
48
|
}
|
|
49
|
+
|
|
44
50
|
const codespan = narrowToken(token, "codespan");
|
|
51
|
+
|
|
45
52
|
if (codespan !== null) {
|
|
46
53
|
result.push(...sink.codespan(codespan, key));
|
|
47
54
|
continue;
|
|
48
55
|
}
|
|
56
|
+
|
|
49
57
|
const link = narrowToken(token, "link");
|
|
58
|
+
|
|
50
59
|
if (link !== null) {
|
|
51
60
|
result.push(...sink.link(link, visitInline(link.tokens, sink, `${key}.`), key));
|
|
52
61
|
continue;
|
|
53
62
|
}
|
|
63
|
+
|
|
54
64
|
const del = narrowToken(token, "del");
|
|
65
|
+
|
|
55
66
|
if (del !== null) {
|
|
56
67
|
result.push(...sink.del(del, visitInline(del.tokens, sink, `${key}.`), key));
|
|
57
68
|
continue;
|
|
58
69
|
}
|
|
70
|
+
|
|
59
71
|
const image = narrowToken(token, "image");
|
|
72
|
+
|
|
60
73
|
if (image !== null) {
|
|
61
74
|
result.push(...sink.image(image, key));
|
|
62
75
|
continue;
|
|
63
76
|
}
|
|
77
|
+
|
|
64
78
|
const br = narrowToken(token, "br");
|
|
79
|
+
|
|
65
80
|
if (br !== null) {
|
|
66
81
|
result.push(...sink.br(br, key));
|
|
67
82
|
continue;
|
|
68
83
|
}
|
|
84
|
+
|
|
69
85
|
const escape = narrowToken(token, "escape");
|
|
86
|
+
|
|
70
87
|
if (escape !== null) {
|
|
71
88
|
result.push(...sink.escape(escape, key));
|
|
72
89
|
continue;
|
|
73
90
|
}
|
|
91
|
+
|
|
74
92
|
const space = narrowToken(token, "space");
|
|
93
|
+
|
|
75
94
|
if (space !== null) {
|
|
76
95
|
result.push(...sink.space(space, key));
|
|
77
96
|
continue;
|
|
78
97
|
}
|
|
98
|
+
|
|
79
99
|
result.push(...sink.fallback(token, key));
|
|
80
100
|
}
|
|
81
101
|
|