@ant-design/x-markdown-mini 0.1.0-beta.0 → 0.1.0-beta.1
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/components/Markdown/index.acss +65 -7
- package/dist/components/MiniNodeRenderer/index.acss +19 -4
- package/dist/components/MiniNodeRenderer/index.axml +109 -29
- package/dist/components/MiniNodeRenderer/index.js +12 -0
- package/dist/components/MiniNodeRenderer/index.sjs +48 -0
- package/dist/es/Markdown/index.acss +65 -7
- package/dist/es/MiniNodeRenderer/index.acss +19 -4
- package/dist/es/MiniNodeRenderer/index.axml +109 -29
- package/dist/es/MiniNodeRenderer/index.js +12 -0
- package/dist/es/MiniNodeRenderer/index.sjs +48 -0
- package/dist/index.d.mts +39 -1
- package/dist/index.d.ts +39 -1
- package/dist/index.js +134 -56
- package/dist/index.mjs +134 -56
- package/dist/miniprogram_dist/components/Markdown/index.json +1 -1
- package/dist/miniprogram_dist/components/Markdown/index.wxss +65 -7
- package/dist/miniprogram_dist/components/MiniNodeRenderer/index.js +12 -0
- package/dist/miniprogram_dist/components/MiniNodeRenderer/index.json +1 -1
- package/dist/miniprogram_dist/components/MiniNodeRenderer/index.wxml +98 -21
- package/dist/miniprogram_dist/components/MiniNodeRenderer/index.wxs +41 -0
- package/dist/miniprogram_dist/components/MiniNodeRenderer/index.wxss +13 -2
- package/dist/miniprogram_dist/es/Markdown/index.json +1 -1
- package/dist/miniprogram_dist/es/Markdown/index.wxss +65 -7
- package/dist/miniprogram_dist/es/MiniNodeRenderer/index.js +12 -0
- package/dist/miniprogram_dist/es/MiniNodeRenderer/index.json +1 -1
- package/dist/miniprogram_dist/es/MiniNodeRenderer/index.wxml +98 -21
- package/dist/miniprogram_dist/es/MiniNodeRenderer/index.wxs +41 -0
- package/dist/miniprogram_dist/es/MiniNodeRenderer/index.wxss +13 -2
- package/dist/miniprogram_dist/index.js +134 -56
- package/dist/miniprogram_dist/plugins/CodeHighlight/index.js +13 -5
- package/dist/miniprogram_dist/plugins/CodeHighlight/style.wxss +41 -31
- package/dist/miniprogram_dist/plugins/Latex/index.js +44 -23
- package/dist/miniprogram_dist/plugins/Latex/style.wxss +11 -11
- package/dist/miniprogram_dist/shared/flattenInline.js +33 -5
- package/dist/plugins/CodeHighlight/index.d.mts +1 -1
- package/dist/plugins/CodeHighlight/index.d.ts +1 -1
- package/dist/plugins/CodeHighlight/index.js +13 -5
- package/dist/plugins/CodeHighlight/index.mjs +13 -5
- package/dist/plugins/CodeHighlight/style.acss +41 -31
- package/dist/plugins/Latex/index.d.mts +1 -1
- package/dist/plugins/Latex/index.d.ts +1 -1
- package/dist/plugins/Latex/index.js +44 -23
- package/dist/plugins/Latex/index.mjs +47 -23
- package/dist/plugins/Latex/style.acss +11 -6
- package/dist/shared/flattenInline.js +33 -5
- package/dist/{types-CegkonfJ.d.mts → types-BcxGtbQZ.d.mts} +25 -0
- package/dist/{types-CegkonfJ.d.ts → types-BcxGtbQZ.d.ts} +25 -0
- package/package.json +3 -2
|
@@ -1,9 +1,23 @@
|
|
|
1
1
|
<import-sjs from="./index.sjs" name="u" />
|
|
2
2
|
|
|
3
3
|
<block a:for="{{nodes}}" a:for-item="node" a:for-index="i" a:key="i">
|
|
4
|
-
<!-- text leaf
|
|
4
|
+
<!-- text leaf: 流式时逐字淡入(Alipay 不能嵌套 <text>,用 inline <view> 包裹字符 <text>,
|
|
5
|
+
按下标 key 复用,只有新字触发动画);非流式时整段渲染为单个 <text>。 -->
|
|
6
|
+
<view
|
|
7
|
+
a:if="{{u.isText(node.name) && animation}}"
|
|
8
|
+
class="md-anim-text {{u.classOf(node)}}"
|
|
9
|
+
>
|
|
10
|
+
<text
|
|
11
|
+
a:for="{{u.charsOf(node)}}"
|
|
12
|
+
a:for-item="ch"
|
|
13
|
+
a:for-index="ci"
|
|
14
|
+
a:key="ci"
|
|
15
|
+
class="md-anim-char"
|
|
16
|
+
selectable="{{selectable}}"
|
|
17
|
+
>{{ch}}</text>
|
|
18
|
+
</view>
|
|
5
19
|
<text
|
|
6
|
-
a:
|
|
20
|
+
a:elif="{{u.isText(node.name)}}"
|
|
7
21
|
class="{{u.classOf(node)}}"
|
|
8
22
|
selectable="{{selectable}}"
|
|
9
23
|
>{{u.valueOf(node)}}</text>
|
|
@@ -26,34 +40,101 @@
|
|
|
26
40
|
onAppear="_appear"
|
|
27
41
|
/>
|
|
28
42
|
|
|
29
|
-
<!-- pre: scrollable
|
|
30
|
-
<
|
|
43
|
+
<!-- pre: code block with language label + copy toolbar, scrollable body -->
|
|
44
|
+
<view
|
|
31
45
|
a:elif="{{u.isPre(node.name)}}"
|
|
32
|
-
|
|
33
|
-
class="{{u.classOf(node)}}"
|
|
34
|
-
style="{{u.styleOf(node)}}"
|
|
35
|
-
data-data="{{node}}"
|
|
36
|
-
catchTap="_tap"
|
|
46
|
+
class="md-codeblock {{node.animate ? 'md-animate-block' : ''}}"
|
|
37
47
|
>
|
|
38
|
-
<
|
|
39
|
-
a:
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
<view a:if="{{node.header}}" class="md-codeblock-bar">
|
|
49
|
+
<block a:for="{{node.header}}" a:for-item="h" a:for-index="hi" a:key="hi">
|
|
50
|
+
<text a:if="{{u.isText(h.name)}}" class="{{u.classOf(h)}}">{{u.valueOf(h)}}</text>
|
|
51
|
+
<image
|
|
52
|
+
a:elif="{{u.isCopy(h.name)}}"
|
|
53
|
+
class="{{u.classOf(h) || 'md-copy-icon'}}"
|
|
54
|
+
src="https://mdn.alipayobjects.com/huamei_y8xg5f/afts/img/JXzqSoHDzm4AAAAAHpAAAAgADuJhAQFr/original"
|
|
55
|
+
data-copy="{{u.copyOf(h)}}"
|
|
56
|
+
catchTap="_copy"
|
|
57
|
+
/>
|
|
58
|
+
<view a:else class="{{u.classOf(h)}}" style="{{u.styleOf(h)}}">
|
|
59
|
+
<mini-node-renderer
|
|
60
|
+
a:if="{{h.children}}"
|
|
61
|
+
nodes="{{h.children}}"
|
|
62
|
+
selectable="{{selectable}}"
|
|
63
|
+
animation="{{false}}"
|
|
64
|
+
slotComponents="{{slotComponents}}"
|
|
65
|
+
onTap="onTap"
|
|
66
|
+
>
|
|
67
|
+
<slot slot-scope="prop" data="{{prop.data}}" />
|
|
68
|
+
</mini-node-renderer>
|
|
69
|
+
</view>
|
|
70
|
+
</block>
|
|
71
|
+
</view>
|
|
72
|
+
<scroll-view scroll-x class="md-code-block">
|
|
73
|
+
<mini-node-renderer
|
|
74
|
+
a:if="{{node.children}}"
|
|
75
|
+
nodes="{{node.children}}"
|
|
76
|
+
selectable="{{selectable}}"
|
|
77
|
+
animation="{{false}}"
|
|
78
|
+
slotComponents="{{slotComponents}}"
|
|
79
|
+
onTap="onTap"
|
|
80
|
+
onAppear="onAppear"
|
|
81
|
+
>
|
|
82
|
+
<slot slot-scope="prop" data="{{prop.data}}" />
|
|
83
|
+
</mini-node-renderer>
|
|
84
|
+
</scroll-view>
|
|
85
|
+
</view>
|
|
86
|
+
|
|
87
|
+
<!-- table: caption + copy toolbar card, horizontal-scroll CSS table (columns kept aligned) -->
|
|
88
|
+
<view
|
|
89
|
+
a:elif="{{u.isTable(node.name)}}"
|
|
90
|
+
class="md-tableblock {{node.animate ? 'md-animate-block' : ''}}"
|
|
91
|
+
>
|
|
92
|
+
<view a:if="{{node.header}}" class="md-tableblock-bar">
|
|
93
|
+
<block a:for="{{node.header}}" a:for-item="h" a:for-index="hi" a:key="hi">
|
|
94
|
+
<text a:if="{{u.isText(h.name)}}" class="{{u.classOf(h)}}">{{u.valueOf(h)}}</text>
|
|
95
|
+
<image
|
|
96
|
+
a:elif="{{u.isCopy(h.name)}}"
|
|
97
|
+
class="{{u.classOf(h) || 'md-copy-icon'}}"
|
|
98
|
+
src="https://mdn.alipayobjects.com/huamei_y8xg5f/afts/img/JXzqSoHDzm4AAAAAHpAAAAgADuJhAQFr/original"
|
|
99
|
+
data-copy="{{u.copyOf(h)}}"
|
|
100
|
+
catchTap="_copy"
|
|
101
|
+
/>
|
|
102
|
+
<view a:else class="{{u.classOf(h)}}" style="{{u.styleOf(h)}}">
|
|
103
|
+
<mini-node-renderer
|
|
104
|
+
a:if="{{h.children}}"
|
|
105
|
+
nodes="{{h.children}}"
|
|
106
|
+
selectable="{{selectable}}"
|
|
107
|
+
animation="{{false}}"
|
|
108
|
+
slotComponents="{{slotComponents}}"
|
|
109
|
+
onTap="onTap"
|
|
110
|
+
>
|
|
111
|
+
<slot slot-scope="prop" data="{{prop.data}}" />
|
|
112
|
+
</mini-node-renderer>
|
|
113
|
+
</view>
|
|
114
|
+
</block>
|
|
115
|
+
</view>
|
|
116
|
+
<scroll-view scroll-x class="md-table-scroll">
|
|
117
|
+
<view class="md-table">
|
|
118
|
+
<mini-node-renderer
|
|
119
|
+
a:if="{{node.children}}"
|
|
120
|
+
nodes="{{node.children}}"
|
|
121
|
+
selectable="{{selectable}}"
|
|
122
|
+
animation="{{false}}"
|
|
123
|
+
slotComponents="{{slotComponents}}"
|
|
124
|
+
onTap="onTap"
|
|
125
|
+
onAppear="onAppear"
|
|
126
|
+
>
|
|
127
|
+
<slot slot-scope="prop" data="{{prop.data}}" />
|
|
128
|
+
</mini-node-renderer>
|
|
129
|
+
</view>
|
|
130
|
+
</scroll-view>
|
|
131
|
+
</view>
|
|
50
132
|
|
|
51
133
|
<!-- anchor: kept interactive, children are already flattened text runs -->
|
|
52
|
-
<
|
|
134
|
+
<view
|
|
53
135
|
a:elif="{{node.name === 'a'}}"
|
|
54
136
|
class="{{u.classOf(node)}}"
|
|
55
137
|
style="{{u.styleOf(node)}}"
|
|
56
|
-
selectable="{{selectable}}"
|
|
57
138
|
data-data="{{node}}"
|
|
58
139
|
catchTap="_tap"
|
|
59
140
|
>
|
|
@@ -64,14 +145,13 @@
|
|
|
64
145
|
a:key="ci"
|
|
65
146
|
class="{{u.classOf(c)}}"
|
|
66
147
|
>{{u.valueOf(c)}}</text>
|
|
67
|
-
</
|
|
148
|
+
</view>
|
|
68
149
|
|
|
69
|
-
<!-- inline tag rendered as
|
|
70
|
-
<
|
|
71
|
-
a:elif="{{u.isInline(node.name)}}"
|
|
150
|
+
<!-- inline tag rendered as a flat container because Alipay SDK 2.x rejects nested <text>. -->
|
|
151
|
+
<view
|
|
152
|
+
a:elif="{{u.isInline(node.name) && !u.isRich(node)}}"
|
|
72
153
|
class="{{u.classOf(node)}}"
|
|
73
154
|
style="{{u.styleOf(node)}}"
|
|
74
|
-
selectable="{{selectable}}"
|
|
75
155
|
data-data="{{node}}"
|
|
76
156
|
catchTap="_tap"
|
|
77
157
|
>
|
|
@@ -82,7 +162,7 @@
|
|
|
82
162
|
a:key="ci"
|
|
83
163
|
class="{{u.classOf(c)}}"
|
|
84
164
|
>{{u.valueOf(c)}}</text>
|
|
85
|
-
</
|
|
165
|
+
</view>
|
|
86
166
|
|
|
87
167
|
<!-- custom component: hand off to host scoped slot, keyed by node.tag -->
|
|
88
168
|
<slot
|
|
@@ -16,6 +16,14 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
16
16
|
// src/components/alipay/MiniNodeRenderer/index.ts
|
|
17
17
|
var MiniNodeRenderer_exports = {};
|
|
18
18
|
module.exports = __toCommonJS(MiniNodeRenderer_exports);
|
|
19
|
+
function copyToClipboard(text) {
|
|
20
|
+
if (!text) return;
|
|
21
|
+
my.setClipboard({
|
|
22
|
+
text,
|
|
23
|
+
success: () => my.showToast({ content: "\u5DF2\u590D\u5236", duration: 1200 }),
|
|
24
|
+
fail: () => my.showToast({ content: "\u590D\u5236\u5931\u8D25" })
|
|
25
|
+
});
|
|
26
|
+
}
|
|
19
27
|
var defaultProps = {
|
|
20
28
|
nodes: [],
|
|
21
29
|
selectable: true,
|
|
@@ -32,6 +40,10 @@ Component({
|
|
|
32
40
|
_appear(e) {
|
|
33
41
|
var _a, _b;
|
|
34
42
|
(_b = (_a = this.props).onAppear) == null ? void 0 : _b.call(_a, e);
|
|
43
|
+
},
|
|
44
|
+
_copy(e) {
|
|
45
|
+
const ds = e && e.currentTarget && e.currentTarget.dataset;
|
|
46
|
+
copyToClipboard(ds && ds.copy || "");
|
|
35
47
|
}
|
|
36
48
|
}
|
|
37
49
|
});
|
|
@@ -13,6 +13,23 @@ function isBr(name) { return name === 'br'; }
|
|
|
13
13
|
function isImg(name) { return name === 'img'; }
|
|
14
14
|
function isHr(name) { return name === 'hr'; }
|
|
15
15
|
function isPre(name) { return name === 'pre'; }
|
|
16
|
+
function isTable(name) { return name === 'table'; }
|
|
17
|
+
function isCopy(name) { return name === 'copy-button'; }
|
|
18
|
+
function copyOf(node) {
|
|
19
|
+
var attrs = node.attrs || {};
|
|
20
|
+
return attrs['data-copy'] || '';
|
|
21
|
+
}
|
|
22
|
+
// 富内联节点(如 KaTeX 公式容器)含有元素子节点,必须走递归 <view> 路径
|
|
23
|
+
// 渲染,保留嵌套结构与 style;普通已扁平化的内联只有 text/br 子节点。
|
|
24
|
+
function isRich(node) {
|
|
25
|
+
var ch = node.children;
|
|
26
|
+
if (!ch) return false;
|
|
27
|
+
for (var i = 0; i < ch.length; i++) {
|
|
28
|
+
var nm = ch[i].name;
|
|
29
|
+
if (nm !== 'text' && nm !== 'br') return true;
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
16
33
|
function isSlot(name, slotComponents) {
|
|
17
34
|
return !!slotComponents && slotComponents.indexOf(name) > -1;
|
|
18
35
|
}
|
|
@@ -26,6 +43,26 @@ function classOf(node) {
|
|
|
26
43
|
return cls;
|
|
27
44
|
}
|
|
28
45
|
|
|
46
|
+
// 把文本拆成「按 code point 安全」的字符数组(不劈坏 emoji/组合 surrogate pair),
|
|
47
|
+
// 供流式逐字淡入:每个字符渲染成独立 <text>,按下标 key 复用,只有新字符会触发淡入动画。
|
|
48
|
+
function charsOf(node) {
|
|
49
|
+
var v = (node.attrs || {}).value || '';
|
|
50
|
+
var out = [];
|
|
51
|
+
var i = 0;
|
|
52
|
+
var n = v.length;
|
|
53
|
+
while (i < n) {
|
|
54
|
+
var code = v.charCodeAt(i);
|
|
55
|
+
if (code >= 55296 && code <= 56319 && i + 1 < n) {
|
|
56
|
+
out.push(v.charAt(i) + v.charAt(i + 1));
|
|
57
|
+
i += 2;
|
|
58
|
+
} else {
|
|
59
|
+
out.push(v.charAt(i));
|
|
60
|
+
i += 1;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return out;
|
|
64
|
+
}
|
|
65
|
+
|
|
29
66
|
function styleOf(node) {
|
|
30
67
|
var attrs = node.attrs || {};
|
|
31
68
|
return attrs.style || '';
|
|
@@ -36,6 +73,11 @@ function srcOf(node) {
|
|
|
36
73
|
return attrs.src || '';
|
|
37
74
|
}
|
|
38
75
|
|
|
76
|
+
function langOf(node) {
|
|
77
|
+
var attrs = node.attrs || {};
|
|
78
|
+
return attrs.lang || '';
|
|
79
|
+
}
|
|
80
|
+
|
|
39
81
|
function altOf(node) {
|
|
40
82
|
var attrs = node.attrs || {};
|
|
41
83
|
return attrs.alt || '';
|
|
@@ -54,10 +96,16 @@ export default {
|
|
|
54
96
|
isImg: isImg,
|
|
55
97
|
isHr: isHr,
|
|
56
98
|
isPre: isPre,
|
|
99
|
+
isTable: isTable,
|
|
100
|
+
isCopy: isCopy,
|
|
101
|
+
copyOf: copyOf,
|
|
102
|
+
isRich: isRich,
|
|
57
103
|
isSlot: isSlot,
|
|
58
104
|
classOf: classOf,
|
|
105
|
+
charsOf: charsOf,
|
|
59
106
|
styleOf: styleOf,
|
|
60
107
|
srcOf: srcOf,
|
|
108
|
+
langOf: langOf,
|
|
61
109
|
altOf: altOf,
|
|
62
110
|
valueOf: valueOf,
|
|
63
111
|
};
|
package/dist/index.d.mts
CHANGED
|
@@ -168,6 +168,22 @@ interface XMarkdownExtension {
|
|
|
168
168
|
/** Marked tokenizer overrides (forwarded to marked). */
|
|
169
169
|
tokenizer?: MarkedExtension['tokenizer'];
|
|
170
170
|
}
|
|
171
|
+
/** Context passed to a code-block header renderer. */
|
|
172
|
+
interface CodeHeaderContext {
|
|
173
|
+
/** Resolved language id ('' when the fence has no language). */
|
|
174
|
+
lang: string;
|
|
175
|
+
/** Raw code text — the clipboard payload. */
|
|
176
|
+
text: string;
|
|
177
|
+
token: Tokens.Code;
|
|
178
|
+
}
|
|
179
|
+
/** Context passed to a table header renderer. */
|
|
180
|
+
interface TableHeaderContext {
|
|
181
|
+
/** Raw markdown source of the table — the clipboard payload. */
|
|
182
|
+
markdown: string;
|
|
183
|
+
token: Tokens.Table;
|
|
184
|
+
}
|
|
185
|
+
type CodeHeaderRenderer = (ctx: CodeHeaderContext) => MiniNode | MiniNode[] | null;
|
|
186
|
+
type TableHeaderRenderer = (ctx: TableHeaderContext) => MiniNode | MiniNode[] | null;
|
|
171
187
|
/** 渲染上下文:transformer 共用的公共配置。 */
|
|
172
188
|
interface RenderContext {
|
|
173
189
|
/** 是否启用块级动画 */
|
|
@@ -184,6 +200,13 @@ interface RenderContext {
|
|
|
184
200
|
* Colocated tokenizer+renderer extensions registered on the instance.
|
|
185
201
|
*/
|
|
186
202
|
extensions?: readonly XMarkdownExtension[];
|
|
203
|
+
/**
|
|
204
|
+
* Code-block header config. `true`/undefined = default (language + copy
|
|
205
|
+
* button); `false` = no header; function = custom header nodes.
|
|
206
|
+
*/
|
|
207
|
+
codeHeader?: boolean | CodeHeaderRenderer;
|
|
208
|
+
/** Table header config. Same semantics as `codeHeader`. */
|
|
209
|
+
tableHeader?: boolean | TableHeaderRenderer;
|
|
187
210
|
/**
|
|
188
211
|
* Recursively render an inline token array to MiniNode[]. Provided by the
|
|
189
212
|
* platform transformer; used by custom extension miniRenderers that emit
|
|
@@ -203,6 +226,8 @@ interface MiniNode {
|
|
|
203
226
|
attrs?: Record<string, string | number | boolean>;
|
|
204
227
|
/** 子节点 */
|
|
205
228
|
children?: MiniNode[];
|
|
229
|
+
/** 代码块/表格顶部 header 栏(语言/标题 + 复制按钮)。 */
|
|
230
|
+
header?: MiniNode[];
|
|
206
231
|
/** 是否开启动画 */
|
|
207
232
|
animate?: boolean;
|
|
208
233
|
}
|
|
@@ -262,6 +287,14 @@ interface XMarkdownMiniOptions {
|
|
|
262
287
|
* `</x>` and will not produce a nested structure.
|
|
263
288
|
*/
|
|
264
289
|
components?: string[];
|
|
290
|
+
/** 代码块 header。true=默认(语言名+复制按钮);false=无;函数=自定义。默认 true。 */
|
|
291
|
+
codeBlock?: {
|
|
292
|
+
header?: boolean | CodeHeaderRenderer;
|
|
293
|
+
};
|
|
294
|
+
/** 表格 header。true=默认(“表格”+复制按钮);false=无;函数=自定义。默认 true。 */
|
|
295
|
+
table?: {
|
|
296
|
+
header?: boolean | TableHeaderRenderer;
|
|
297
|
+
};
|
|
265
298
|
}
|
|
266
299
|
/**
|
|
267
300
|
* Independent renderer instance with isolated streaming state.
|
|
@@ -274,6 +307,8 @@ declare class XMarkdownMini {
|
|
|
274
307
|
private readonly fixup;
|
|
275
308
|
private readonly gfm;
|
|
276
309
|
private readonly breaks;
|
|
310
|
+
private readonly codeHeader;
|
|
311
|
+
private readonly tableHeader;
|
|
277
312
|
private readonly marked;
|
|
278
313
|
private activeTokenStreamDefaults;
|
|
279
314
|
private activeNodeStreamDefaults;
|
|
@@ -434,6 +469,9 @@ declare class StreamingProcessor<T = unknown> {
|
|
|
434
469
|
private flushNodes;
|
|
435
470
|
}
|
|
436
471
|
|
|
472
|
+
/** Build a copy-button MiniNode carrying the raw clipboard payload. */
|
|
473
|
+
declare function copyButton(text: string): MiniNode;
|
|
474
|
+
|
|
437
475
|
/**
|
|
438
476
|
* 自包含行内脚注扩展。
|
|
439
477
|
*
|
|
@@ -505,4 +543,4 @@ declare function render(props: XMarkdownMiniTokenProps): Token[];
|
|
|
505
543
|
*/
|
|
506
544
|
declare function renderNodes(props: XMarkdownMiniProps): MiniNode[];
|
|
507
545
|
|
|
508
|
-
export { type BuiltinPlatform, type FlattenInlineTokensOptions, Footnote, type FootnoteOptions, type InlineRun, type InlineRunKind, type MiniNode, type Platform, type PlatformCapabilities, type PlatformInput, type PlatformRenderer, type RenderContext, type SemanticStreamingConfig, type StreamingConfig, type StreamingFixup, StreamingProcessor, type XMarkdownExtension, XMarkdownMini, type XMarkdownMiniOptions, type XMarkdownMiniProps, type XMarkdownMiniTokenProps, type XMarkdownTokenizerExtension, alipayRenderer, flattenInlineTokens, getPlatformRenderer, parse, registerPlatformRenderer, render, renderNodes, resolvePlatform, tokensToAlipay, tokensToAlipayNodes, tokensToWechat, tokensToWechatNodes, wechatRenderer };
|
|
546
|
+
export { type BuiltinPlatform, type CodeHeaderContext, type CodeHeaderRenderer, type FlattenInlineTokensOptions, Footnote, type FootnoteOptions, type InlineRun, type InlineRunKind, type MiniNode, type Platform, type PlatformCapabilities, type PlatformInput, type PlatformRenderer, type RenderContext, type SemanticStreamingConfig, type StreamingConfig, type StreamingFixup, StreamingProcessor, type TableHeaderContext, type TableHeaderRenderer, type XMarkdownExtension, XMarkdownMini, type XMarkdownMiniOptions, type XMarkdownMiniProps, type XMarkdownMiniTokenProps, type XMarkdownTokenizerExtension, alipayRenderer, copyButton, flattenInlineTokens, getPlatformRenderer, parse, registerPlatformRenderer, render, renderNodes, resolvePlatform, tokensToAlipay, tokensToAlipayNodes, tokensToWechat, tokensToWechatNodes, wechatRenderer };
|
package/dist/index.d.ts
CHANGED
|
@@ -168,6 +168,22 @@ interface XMarkdownExtension {
|
|
|
168
168
|
/** Marked tokenizer overrides (forwarded to marked). */
|
|
169
169
|
tokenizer?: MarkedExtension['tokenizer'];
|
|
170
170
|
}
|
|
171
|
+
/** Context passed to a code-block header renderer. */
|
|
172
|
+
interface CodeHeaderContext {
|
|
173
|
+
/** Resolved language id ('' when the fence has no language). */
|
|
174
|
+
lang: string;
|
|
175
|
+
/** Raw code text — the clipboard payload. */
|
|
176
|
+
text: string;
|
|
177
|
+
token: Tokens.Code;
|
|
178
|
+
}
|
|
179
|
+
/** Context passed to a table header renderer. */
|
|
180
|
+
interface TableHeaderContext {
|
|
181
|
+
/** Raw markdown source of the table — the clipboard payload. */
|
|
182
|
+
markdown: string;
|
|
183
|
+
token: Tokens.Table;
|
|
184
|
+
}
|
|
185
|
+
type CodeHeaderRenderer = (ctx: CodeHeaderContext) => MiniNode | MiniNode[] | null;
|
|
186
|
+
type TableHeaderRenderer = (ctx: TableHeaderContext) => MiniNode | MiniNode[] | null;
|
|
171
187
|
/** 渲染上下文:transformer 共用的公共配置。 */
|
|
172
188
|
interface RenderContext {
|
|
173
189
|
/** 是否启用块级动画 */
|
|
@@ -184,6 +200,13 @@ interface RenderContext {
|
|
|
184
200
|
* Colocated tokenizer+renderer extensions registered on the instance.
|
|
185
201
|
*/
|
|
186
202
|
extensions?: readonly XMarkdownExtension[];
|
|
203
|
+
/**
|
|
204
|
+
* Code-block header config. `true`/undefined = default (language + copy
|
|
205
|
+
* button); `false` = no header; function = custom header nodes.
|
|
206
|
+
*/
|
|
207
|
+
codeHeader?: boolean | CodeHeaderRenderer;
|
|
208
|
+
/** Table header config. Same semantics as `codeHeader`. */
|
|
209
|
+
tableHeader?: boolean | TableHeaderRenderer;
|
|
187
210
|
/**
|
|
188
211
|
* Recursively render an inline token array to MiniNode[]. Provided by the
|
|
189
212
|
* platform transformer; used by custom extension miniRenderers that emit
|
|
@@ -203,6 +226,8 @@ interface MiniNode {
|
|
|
203
226
|
attrs?: Record<string, string | number | boolean>;
|
|
204
227
|
/** 子节点 */
|
|
205
228
|
children?: MiniNode[];
|
|
229
|
+
/** 代码块/表格顶部 header 栏(语言/标题 + 复制按钮)。 */
|
|
230
|
+
header?: MiniNode[];
|
|
206
231
|
/** 是否开启动画 */
|
|
207
232
|
animate?: boolean;
|
|
208
233
|
}
|
|
@@ -262,6 +287,14 @@ interface XMarkdownMiniOptions {
|
|
|
262
287
|
* `</x>` and will not produce a nested structure.
|
|
263
288
|
*/
|
|
264
289
|
components?: string[];
|
|
290
|
+
/** 代码块 header。true=默认(语言名+复制按钮);false=无;函数=自定义。默认 true。 */
|
|
291
|
+
codeBlock?: {
|
|
292
|
+
header?: boolean | CodeHeaderRenderer;
|
|
293
|
+
};
|
|
294
|
+
/** 表格 header。true=默认(“表格”+复制按钮);false=无;函数=自定义。默认 true。 */
|
|
295
|
+
table?: {
|
|
296
|
+
header?: boolean | TableHeaderRenderer;
|
|
297
|
+
};
|
|
265
298
|
}
|
|
266
299
|
/**
|
|
267
300
|
* Independent renderer instance with isolated streaming state.
|
|
@@ -274,6 +307,8 @@ declare class XMarkdownMini {
|
|
|
274
307
|
private readonly fixup;
|
|
275
308
|
private readonly gfm;
|
|
276
309
|
private readonly breaks;
|
|
310
|
+
private readonly codeHeader;
|
|
311
|
+
private readonly tableHeader;
|
|
277
312
|
private readonly marked;
|
|
278
313
|
private activeTokenStreamDefaults;
|
|
279
314
|
private activeNodeStreamDefaults;
|
|
@@ -434,6 +469,9 @@ declare class StreamingProcessor<T = unknown> {
|
|
|
434
469
|
private flushNodes;
|
|
435
470
|
}
|
|
436
471
|
|
|
472
|
+
/** Build a copy-button MiniNode carrying the raw clipboard payload. */
|
|
473
|
+
declare function copyButton(text: string): MiniNode;
|
|
474
|
+
|
|
437
475
|
/**
|
|
438
476
|
* 自包含行内脚注扩展。
|
|
439
477
|
*
|
|
@@ -505,4 +543,4 @@ declare function render(props: XMarkdownMiniTokenProps): Token[];
|
|
|
505
543
|
*/
|
|
506
544
|
declare function renderNodes(props: XMarkdownMiniProps): MiniNode[];
|
|
507
545
|
|
|
508
|
-
export { type BuiltinPlatform, type FlattenInlineTokensOptions, Footnote, type FootnoteOptions, type InlineRun, type InlineRunKind, type MiniNode, type Platform, type PlatformCapabilities, type PlatformInput, type PlatformRenderer, type RenderContext, type SemanticStreamingConfig, type StreamingConfig, type StreamingFixup, StreamingProcessor, type XMarkdownExtension, XMarkdownMini, type XMarkdownMiniOptions, type XMarkdownMiniProps, type XMarkdownMiniTokenProps, type XMarkdownTokenizerExtension, alipayRenderer, flattenInlineTokens, getPlatformRenderer, parse, registerPlatformRenderer, render, renderNodes, resolvePlatform, tokensToAlipay, tokensToAlipayNodes, tokensToWechat, tokensToWechatNodes, wechatRenderer };
|
|
546
|
+
export { type BuiltinPlatform, type CodeHeaderContext, type CodeHeaderRenderer, type FlattenInlineTokensOptions, Footnote, type FootnoteOptions, type InlineRun, type InlineRunKind, type MiniNode, type Platform, type PlatformCapabilities, type PlatformInput, type PlatformRenderer, type RenderContext, type SemanticStreamingConfig, type StreamingConfig, type StreamingFixup, StreamingProcessor, type TableHeaderContext, type TableHeaderRenderer, type XMarkdownExtension, XMarkdownMini, type XMarkdownMiniOptions, type XMarkdownMiniProps, type XMarkdownMiniTokenProps, type XMarkdownTokenizerExtension, alipayRenderer, copyButton, flattenInlineTokens, getPlatformRenderer, parse, registerPlatformRenderer, render, renderNodes, resolvePlatform, tokensToAlipay, tokensToAlipayNodes, tokensToWechat, tokensToWechatNodes, wechatRenderer };
|