@athenaintel/react 0.14.0 → 0.15.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/chat/ComposerEditorContext.d.ts +6 -0
- package/dist/chat-ui/composer/composer-action.d.ts +8 -1
- package/dist/chat-ui/index.d.ts +2 -2
- package/dist/chat-ui/messages/message-components.d.ts +8 -6
- package/dist/chat-ui/thread/chat-composer-dock.d.ts +13 -1
- package/dist/chat-ui/thread/chat-thread-shell.d.ts +57 -6
- package/dist/chat-ui/thread/composer-send-or-stop.d.ts +25 -2
- package/dist/chat-ui.cjs +176 -4309
- package/dist/chat-ui.cjs.map +1 -1
- package/dist/chat-ui.js +82 -4214
- package/dist/chat-ui.js.map +1 -1
- package/dist/{scope-registry-B9XYV-FT.js → composer-send-or-stop-C5AVmcwO.js} +5471 -1218
- package/dist/composer-send-or-stop-C5AVmcwO.js.map +1 -0
- package/dist/{scope-registry-Bti8l_Xy.cjs → composer-send-or-stop-RPudYkWR.cjs} +5460 -1207
- package/dist/composer-send-or-stop-RPudYkWR.cjs.map +1 -0
- package/dist/index.cjs +516 -515
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +120 -119
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/scope-registry-B9XYV-FT.js.map +0 -1
- package/dist/scope-registry-Bti8l_Xy.cjs.map +0 -1
package/dist/chat-ui.cjs
CHANGED
|
@@ -3,12 +3,10 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
4
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
5
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
6
|
+
const composerSendOrStop = require("./composer-send-or-stop-RPudYkWR.cjs");
|
|
6
7
|
const jsxRuntime = require("react/jsx-runtime");
|
|
7
|
-
const react = require("@assistant-ui/react");
|
|
8
|
-
const reactMarkdown = require("@assistant-ui/react-markdown");
|
|
9
|
-
require("@assistant-ui/react-markdown/styles/dot.css");
|
|
10
8
|
const React = require("react");
|
|
11
|
-
const
|
|
9
|
+
const react = require("@assistant-ui/react");
|
|
12
10
|
require("@assistant-ui/tap");
|
|
13
11
|
require("statewire");
|
|
14
12
|
require("@assistant-ui/store");
|
|
@@ -28,7 +26,7 @@ function registerChatAssetMentionHandler(threadId, handler) {
|
|
|
28
26
|
* This source code is licensed under the ISC license.
|
|
29
27
|
* See the LICENSE file in the root directory of this source tree.
|
|
30
28
|
*/
|
|
31
|
-
const __iconNode$
|
|
29
|
+
const __iconNode$k = [
|
|
32
30
|
["path", { d: "M10 12h4", key: "a56b0p" }],
|
|
33
31
|
["path", { d: "M10 8h4", key: "1sr2af" }],
|
|
34
32
|
["path", { d: "M14 21v-3a2 2 0 0 0-4 0v3", key: "1rgiei" }],
|
|
@@ -41,51 +39,24 @@ const __iconNode$n = [
|
|
|
41
39
|
],
|
|
42
40
|
["path", { d: "M6 21V5a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v16", key: "16ra0t" }]
|
|
43
41
|
];
|
|
44
|
-
const Building2 =
|
|
45
|
-
/**
|
|
46
|
-
* @license lucide-react v0.575.0 - ISC
|
|
47
|
-
*
|
|
48
|
-
* This source code is licensed under the ISC license.
|
|
49
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
50
|
-
*/
|
|
51
|
-
const __iconNode$m = [["path", { d: "m15 18-6-6 6-6", key: "1wnfg3" }]];
|
|
52
|
-
const ChevronLeft = scopeRegistry.createLucideIcon("chevron-left", __iconNode$m);
|
|
42
|
+
const Building2 = composerSendOrStop.createLucideIcon("building-2", __iconNode$k);
|
|
53
43
|
/**
|
|
54
44
|
* @license lucide-react v0.575.0 - ISC
|
|
55
45
|
*
|
|
56
46
|
* This source code is licensed under the ISC license.
|
|
57
47
|
* See the LICENSE file in the root directory of this source tree.
|
|
58
48
|
*/
|
|
59
|
-
const __iconNode$
|
|
49
|
+
const __iconNode$j = [
|
|
60
50
|
["path", { d: "M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z", key: "p7xjir" }]
|
|
61
51
|
];
|
|
62
|
-
const Cloud =
|
|
63
|
-
/**
|
|
64
|
-
* @license lucide-react v0.575.0 - ISC
|
|
65
|
-
*
|
|
66
|
-
* This source code is licensed under the ISC license.
|
|
67
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
68
|
-
*/
|
|
69
|
-
const __iconNode$k = [
|
|
70
|
-
["path", { d: "M21.54 15H17a2 2 0 0 0-2 2v4.54", key: "1djwo0" }],
|
|
71
|
-
[
|
|
72
|
-
"path",
|
|
73
|
-
{
|
|
74
|
-
d: "M7 3.34V5a3 3 0 0 0 3 3a2 2 0 0 1 2 2c0 1.1.9 2 2 2a2 2 0 0 0 2-2c0-1.1.9-2 2-2h3.17",
|
|
75
|
-
key: "1tzkfa"
|
|
76
|
-
}
|
|
77
|
-
],
|
|
78
|
-
["path", { d: "M11 21.95V18a2 2 0 0 0-2-2a2 2 0 0 1-2-2v-1a2 2 0 0 0-2-2H2.05", key: "14pb5j" }],
|
|
79
|
-
["circle", { cx: "12", cy: "12", r: "10", key: "1mglay" }]
|
|
80
|
-
];
|
|
81
|
-
const Earth = scopeRegistry.createLucideIcon("earth", __iconNode$k);
|
|
52
|
+
const Cloud = composerSendOrStop.createLucideIcon("cloud", __iconNode$j);
|
|
82
53
|
/**
|
|
83
54
|
* @license lucide-react v0.575.0 - ISC
|
|
84
55
|
*
|
|
85
56
|
* This source code is licensed under the ISC license.
|
|
86
57
|
* See the LICENSE file in the root directory of this source tree.
|
|
87
58
|
*/
|
|
88
|
-
const __iconNode$
|
|
59
|
+
const __iconNode$i = [
|
|
89
60
|
[
|
|
90
61
|
"path",
|
|
91
62
|
{
|
|
@@ -95,14 +66,14 @@ const __iconNode$j = [
|
|
|
95
66
|
],
|
|
96
67
|
["circle", { cx: "12", cy: "12", r: "3", key: "1v7zrd" }]
|
|
97
68
|
];
|
|
98
|
-
const Eye =
|
|
69
|
+
const Eye = composerSendOrStop.createLucideIcon("eye", __iconNode$i);
|
|
99
70
|
/**
|
|
100
71
|
* @license lucide-react v0.575.0 - ISC
|
|
101
72
|
*
|
|
102
73
|
* This source code is licensed under the ISC license.
|
|
103
74
|
* See the LICENSE file in the root directory of this source tree.
|
|
104
75
|
*/
|
|
105
|
-
const __iconNode$
|
|
76
|
+
const __iconNode$h = [
|
|
106
77
|
[
|
|
107
78
|
"path",
|
|
108
79
|
{
|
|
@@ -114,14 +85,14 @@ const __iconNode$i = [
|
|
|
114
85
|
["path", { d: "M10 12.5 8 15l2 2.5", key: "1tg20x" }],
|
|
115
86
|
["path", { d: "m14 12.5 2 2.5-2 2.5", key: "yinavb" }]
|
|
116
87
|
];
|
|
117
|
-
const FileCode =
|
|
88
|
+
const FileCode = composerSendOrStop.createLucideIcon("file-code", __iconNode$h);
|
|
118
89
|
/**
|
|
119
90
|
* @license lucide-react v0.575.0 - ISC
|
|
120
91
|
*
|
|
121
92
|
* This source code is licensed under the ISC license.
|
|
122
93
|
* See the LICENSE file in the root directory of this source tree.
|
|
123
94
|
*/
|
|
124
|
-
const __iconNode$
|
|
95
|
+
const __iconNode$g = [
|
|
125
96
|
[
|
|
126
97
|
"path",
|
|
127
98
|
{
|
|
@@ -130,26 +101,26 @@ const __iconNode$h = [
|
|
|
130
101
|
}
|
|
131
102
|
]
|
|
132
103
|
];
|
|
133
|
-
const Headphones =
|
|
104
|
+
const Headphones = composerSendOrStop.createLucideIcon("headphones", __iconNode$g);
|
|
134
105
|
/**
|
|
135
106
|
* @license lucide-react v0.575.0 - ISC
|
|
136
107
|
*
|
|
137
108
|
* This source code is licensed under the ISC license.
|
|
138
109
|
* See the LICENSE file in the root directory of this source tree.
|
|
139
110
|
*/
|
|
140
|
-
const __iconNode$
|
|
111
|
+
const __iconNode$f = [
|
|
141
112
|
["path", { d: "m15.5 7.5 2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4", key: "g0fldk" }],
|
|
142
113
|
["path", { d: "m21 2-9.6 9.6", key: "1j0ho8" }],
|
|
143
114
|
["circle", { cx: "7.5", cy: "15.5", r: "5.5", key: "yqb3hr" }]
|
|
144
115
|
];
|
|
145
|
-
const Key =
|
|
116
|
+
const Key = composerSendOrStop.createLucideIcon("key", __iconNode$f);
|
|
146
117
|
/**
|
|
147
118
|
* @license lucide-react v0.575.0 - ISC
|
|
148
119
|
*
|
|
149
120
|
* This source code is licensed under the ISC license.
|
|
150
121
|
* See the LICENSE file in the root directory of this source tree.
|
|
151
122
|
*/
|
|
152
|
-
const __iconNode$
|
|
123
|
+
const __iconNode$e = [
|
|
153
124
|
["path", { d: "M10 8h.01", key: "1r9ogq" }],
|
|
154
125
|
["path", { d: "M12 12h.01", key: "1mp3jc" }],
|
|
155
126
|
["path", { d: "M14 8h.01", key: "1primd" }],
|
|
@@ -160,47 +131,33 @@ const __iconNode$f = [
|
|
|
160
131
|
["path", { d: "M8 12h.01", key: "czm47f" }],
|
|
161
132
|
["rect", { width: "20", height: "16", x: "2", y: "4", rx: "2", key: "18n3k1" }]
|
|
162
133
|
];
|
|
163
|
-
const Keyboard =
|
|
134
|
+
const Keyboard = composerSendOrStop.createLucideIcon("keyboard", __iconNode$e);
|
|
164
135
|
/**
|
|
165
136
|
* @license lucide-react v0.575.0 - ISC
|
|
166
137
|
*
|
|
167
138
|
* This source code is licensed under the ISC license.
|
|
168
139
|
* See the LICENSE file in the root directory of this source tree.
|
|
169
140
|
*/
|
|
170
|
-
const __iconNode$
|
|
141
|
+
const __iconNode$d = [
|
|
171
142
|
["rect", { width: "7", height: "9", x: "3", y: "3", rx: "1", key: "10lvy0" }],
|
|
172
143
|
["rect", { width: "7", height: "5", x: "14", y: "3", rx: "1", key: "16une8" }],
|
|
173
144
|
["rect", { width: "7", height: "9", x: "14", y: "12", rx: "1", key: "1hutg5" }],
|
|
174
145
|
["rect", { width: "7", height: "5", x: "3", y: "16", rx: "1", key: "ldoo1y" }]
|
|
175
146
|
];
|
|
176
|
-
const LayoutDashboard =
|
|
147
|
+
const LayoutDashboard = composerSendOrStop.createLucideIcon("layout-dashboard", __iconNode$d);
|
|
177
148
|
/**
|
|
178
149
|
* @license lucide-react v0.575.0 - ISC
|
|
179
150
|
*
|
|
180
151
|
* This source code is licensed under the ISC license.
|
|
181
152
|
* See the LICENSE file in the root directory of this source tree.
|
|
182
153
|
*/
|
|
183
|
-
const __iconNode$
|
|
154
|
+
const __iconNode$c = [
|
|
184
155
|
["path", { d: "m16 6 4 14", key: "ji33uf" }],
|
|
185
156
|
["path", { d: "M12 6v14", key: "1n7gus" }],
|
|
186
157
|
["path", { d: "M8 8v12", key: "1gg7y9" }],
|
|
187
158
|
["path", { d: "M4 4v16", key: "6qkkli" }]
|
|
188
159
|
];
|
|
189
|
-
const Library =
|
|
190
|
-
/**
|
|
191
|
-
* @license lucide-react v0.575.0 - ISC
|
|
192
|
-
*
|
|
193
|
-
* This source code is licensed under the ISC license.
|
|
194
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
195
|
-
*/
|
|
196
|
-
const __iconNode$c = [
|
|
197
|
-
["path", { d: "M16 5H3", key: "m91uny" }],
|
|
198
|
-
["path", { d: "M11 12H3", key: "51ecnj" }],
|
|
199
|
-
["path", { d: "M16 19H3", key: "zzsher" }],
|
|
200
|
-
["path", { d: "M18 9v6", key: "1twb98" }],
|
|
201
|
-
["path", { d: "M21 12h-6", key: "bt1uis" }]
|
|
202
|
-
];
|
|
203
|
-
const ListPlus = scopeRegistry.createLucideIcon("list-plus", __iconNode$c);
|
|
160
|
+
const Library = composerSendOrStop.createLucideIcon("library", __iconNode$c);
|
|
204
161
|
/**
|
|
205
162
|
* @license lucide-react v0.575.0 - ISC
|
|
206
163
|
*
|
|
@@ -212,7 +169,7 @@ const __iconNode$b = [
|
|
|
212
169
|
["path", { d: "M19 10v2a7 7 0 0 1-14 0v-2", key: "1vc78b" }],
|
|
213
170
|
["rect", { x: "9", y: "2", width: "6", height: "13", rx: "3", key: "s6n7sd" }]
|
|
214
171
|
];
|
|
215
|
-
const Mic =
|
|
172
|
+
const Mic = composerSendOrStop.createLucideIcon("mic", __iconNode$b);
|
|
216
173
|
/**
|
|
217
174
|
* @license lucide-react v0.575.0 - ISC
|
|
218
175
|
*
|
|
@@ -232,7 +189,7 @@ const __iconNode$a = [
|
|
|
232
189
|
["circle", { cx: "6.5", cy: "12.5", r: ".5", fill: "currentColor", key: "qy21gx" }],
|
|
233
190
|
["circle", { cx: "8.5", cy: "7.5", r: ".5", fill: "currentColor", key: "fotxhn" }]
|
|
234
191
|
];
|
|
235
|
-
const Palette =
|
|
192
|
+
const Palette = composerSendOrStop.createLucideIcon("palette", __iconNode$a);
|
|
236
193
|
/**
|
|
237
194
|
* @license lucide-react v0.575.0 - ISC
|
|
238
195
|
*
|
|
@@ -244,7 +201,7 @@ const __iconNode$9 = [
|
|
|
244
201
|
["path", { d: "M3 9h18", key: "1pudct" }],
|
|
245
202
|
["path", { d: "M9 21V9", key: "1oto5p" }]
|
|
246
203
|
];
|
|
247
|
-
const PanelsTopLeft =
|
|
204
|
+
const PanelsTopLeft = composerSendOrStop.createLucideIcon("panels-top-left", __iconNode$9);
|
|
248
205
|
/**
|
|
249
206
|
* @license lucide-react v0.575.0 - ISC
|
|
250
207
|
*
|
|
@@ -269,7 +226,7 @@ const __iconNode$8 = [
|
|
|
269
226
|
["path", { d: "m2.3 2.3 7.286 7.286", key: "1wuzzi" }],
|
|
270
227
|
["circle", { cx: "11", cy: "11", r: "2", key: "xmgehs" }]
|
|
271
228
|
];
|
|
272
|
-
const PenTool =
|
|
229
|
+
const PenTool = composerSendOrStop.createLucideIcon("pen-tool", __iconNode$8);
|
|
273
230
|
/**
|
|
274
231
|
* @license lucide-react v0.575.0 - ISC
|
|
275
232
|
*
|
|
@@ -285,7 +242,7 @@ const __iconNode$7 = [
|
|
|
285
242
|
}
|
|
286
243
|
]
|
|
287
244
|
];
|
|
288
|
-
const Phone =
|
|
245
|
+
const Phone = composerSendOrStop.createLucideIcon("phone", __iconNode$7);
|
|
289
246
|
/**
|
|
290
247
|
* @license lucide-react v0.575.0 - ISC
|
|
291
248
|
*
|
|
@@ -296,7 +253,7 @@ const __iconNode$6 = [
|
|
|
296
253
|
["rect", { width: "14", height: "20", x: "5", y: "2", rx: "2", ry: "2", key: "1yt0o3" }],
|
|
297
254
|
["path", { d: "M12 18h.01", key: "mhygvu" }]
|
|
298
255
|
];
|
|
299
|
-
const Smartphone =
|
|
256
|
+
const Smartphone = composerSendOrStop.createLucideIcon("smartphone", __iconNode$6);
|
|
300
257
|
/**
|
|
301
258
|
* @license lucide-react v0.575.0 - ISC
|
|
302
259
|
*
|
|
@@ -315,7 +272,7 @@ const __iconNode$5 = [
|
|
|
315
272
|
["path", { d: "M22 4h-4", key: "gwowj6" }],
|
|
316
273
|
["circle", { cx: "4", cy: "20", r: "2", key: "6kqj1y" }]
|
|
317
274
|
];
|
|
318
|
-
const Sparkles =
|
|
275
|
+
const Sparkles = composerSendOrStop.createLucideIcon("sparkles", __iconNode$5);
|
|
319
276
|
/**
|
|
320
277
|
* @license lucide-react v0.575.0 - ISC
|
|
321
278
|
*
|
|
@@ -329,7 +286,7 @@ const __iconNode$4 = [
|
|
|
329
286
|
],
|
|
330
287
|
["path", { d: "m9 11 3 3L22 4", key: "1pflzl" }]
|
|
331
288
|
];
|
|
332
|
-
const SquareCheckBig =
|
|
289
|
+
const SquareCheckBig = composerSendOrStop.createLucideIcon("square-check-big", __iconNode$4);
|
|
333
290
|
/**
|
|
334
291
|
* @license lucide-react v0.575.0 - ISC
|
|
335
292
|
*
|
|
@@ -345,7 +302,7 @@ const __iconNode$3 = [
|
|
|
345
302
|
}
|
|
346
303
|
]
|
|
347
304
|
];
|
|
348
|
-
const Star =
|
|
305
|
+
const Star = composerSendOrStop.createLucideIcon("star", __iconNode$3);
|
|
349
306
|
/**
|
|
350
307
|
* @license lucide-react v0.575.0 - ISC
|
|
351
308
|
*
|
|
@@ -356,7 +313,7 @@ const __iconNode$2 = [
|
|
|
356
313
|
["path", { d: "M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2", key: "975kel" }],
|
|
357
314
|
["circle", { cx: "12", cy: "7", r: "4", key: "17ys0d" }]
|
|
358
315
|
];
|
|
359
|
-
const User =
|
|
316
|
+
const User = composerSendOrStop.createLucideIcon("user", __iconNode$2);
|
|
360
317
|
/**
|
|
361
318
|
* @license lucide-react v0.575.0 - ISC
|
|
362
319
|
*
|
|
@@ -373,7 +330,7 @@ const __iconNode$1 = [
|
|
|
373
330
|
],
|
|
374
331
|
["rect", { x: "2", y: "6", width: "14", height: "12", rx: "2", key: "158x01" }]
|
|
375
332
|
];
|
|
376
|
-
const Video =
|
|
333
|
+
const Video = composerSendOrStop.createLucideIcon("video", __iconNode$1);
|
|
377
334
|
/**
|
|
378
335
|
* @license lucide-react v0.575.0 - ISC
|
|
379
336
|
*
|
|
@@ -389,4097 +346,7 @@ const __iconNode = [
|
|
|
389
346
|
}
|
|
390
347
|
]
|
|
391
348
|
];
|
|
392
|
-
const Zap =
|
|
393
|
-
function ccount(value, character) {
|
|
394
|
-
const source = String(value);
|
|
395
|
-
if (typeof character !== "string") {
|
|
396
|
-
throw new TypeError("Expected character");
|
|
397
|
-
}
|
|
398
|
-
let count = 0;
|
|
399
|
-
let index = source.indexOf(character);
|
|
400
|
-
while (index !== -1) {
|
|
401
|
-
count++;
|
|
402
|
-
index = source.indexOf(character, index + character.length);
|
|
403
|
-
}
|
|
404
|
-
return count;
|
|
405
|
-
}
|
|
406
|
-
function ok$1() {
|
|
407
|
-
}
|
|
408
|
-
const asciiAlpha = regexCheck(/[A-Za-z]/);
|
|
409
|
-
const asciiAlphanumeric = regexCheck(/[\dA-Za-z]/);
|
|
410
|
-
function asciiControl(code2) {
|
|
411
|
-
return (
|
|
412
|
-
// Special whitespace codes (which have negative values), C0 and Control
|
|
413
|
-
// character DEL
|
|
414
|
-
code2 !== null && (code2 < 32 || code2 === 127)
|
|
415
|
-
);
|
|
416
|
-
}
|
|
417
|
-
function markdownLineEnding(code2) {
|
|
418
|
-
return code2 !== null && code2 < -2;
|
|
419
|
-
}
|
|
420
|
-
function markdownLineEndingOrSpace(code2) {
|
|
421
|
-
return code2 !== null && (code2 < 0 || code2 === 32);
|
|
422
|
-
}
|
|
423
|
-
function markdownSpace(code2) {
|
|
424
|
-
return code2 === -2 || code2 === -1 || code2 === 32;
|
|
425
|
-
}
|
|
426
|
-
const unicodePunctuation = regexCheck(new RegExp("\\p{P}|\\p{S}", "u"));
|
|
427
|
-
const unicodeWhitespace = regexCheck(/\s/);
|
|
428
|
-
function regexCheck(regex) {
|
|
429
|
-
return check;
|
|
430
|
-
function check(code2) {
|
|
431
|
-
return code2 !== null && code2 > -1 && regex.test(String.fromCharCode(code2));
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
function escapeStringRegexp(string) {
|
|
435
|
-
if (typeof string !== "string") {
|
|
436
|
-
throw new TypeError("Expected a string");
|
|
437
|
-
}
|
|
438
|
-
return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
|
|
439
|
-
}
|
|
440
|
-
const convert = (
|
|
441
|
-
// Note: overloads in JSDoc can’t yet use different `@template`s.
|
|
442
|
-
/**
|
|
443
|
-
* @type {(
|
|
444
|
-
* (<Condition extends string>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & {type: Condition}) &
|
|
445
|
-
* (<Condition extends Props>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & Condition) &
|
|
446
|
-
* (<Condition extends TestFunction>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & Predicate<Condition, Node>) &
|
|
447
|
-
* ((test?: null | undefined) => (node?: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node) &
|
|
448
|
-
* ((test?: Test) => Check)
|
|
449
|
-
* )}
|
|
450
|
-
*/
|
|
451
|
-
/**
|
|
452
|
-
* @param {Test} [test]
|
|
453
|
-
* @returns {Check}
|
|
454
|
-
*/
|
|
455
|
-
(function(test) {
|
|
456
|
-
if (test === null || test === void 0) {
|
|
457
|
-
return ok;
|
|
458
|
-
}
|
|
459
|
-
if (typeof test === "function") {
|
|
460
|
-
return castFactory(test);
|
|
461
|
-
}
|
|
462
|
-
if (typeof test === "object") {
|
|
463
|
-
return Array.isArray(test) ? anyFactory(test) : (
|
|
464
|
-
// Cast because `ReadonlyArray` goes into the above but `isArray`
|
|
465
|
-
// narrows to `Array`.
|
|
466
|
-
propertiesFactory(
|
|
467
|
-
/** @type {Props} */
|
|
468
|
-
test
|
|
469
|
-
)
|
|
470
|
-
);
|
|
471
|
-
}
|
|
472
|
-
if (typeof test === "string") {
|
|
473
|
-
return typeFactory(test);
|
|
474
|
-
}
|
|
475
|
-
throw new Error("Expected function, string, or object as test");
|
|
476
|
-
})
|
|
477
|
-
);
|
|
478
|
-
function anyFactory(tests) {
|
|
479
|
-
const checks = [];
|
|
480
|
-
let index = -1;
|
|
481
|
-
while (++index < tests.length) {
|
|
482
|
-
checks[index] = convert(tests[index]);
|
|
483
|
-
}
|
|
484
|
-
return castFactory(any);
|
|
485
|
-
function any(...parameters) {
|
|
486
|
-
let index2 = -1;
|
|
487
|
-
while (++index2 < checks.length) {
|
|
488
|
-
if (checks[index2].apply(this, parameters)) return true;
|
|
489
|
-
}
|
|
490
|
-
return false;
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
function propertiesFactory(check) {
|
|
494
|
-
const checkAsRecord = (
|
|
495
|
-
/** @type {Record<string, unknown>} */
|
|
496
|
-
check
|
|
497
|
-
);
|
|
498
|
-
return castFactory(all2);
|
|
499
|
-
function all2(node2) {
|
|
500
|
-
const nodeAsRecord = (
|
|
501
|
-
/** @type {Record<string, unknown>} */
|
|
502
|
-
/** @type {unknown} */
|
|
503
|
-
node2
|
|
504
|
-
);
|
|
505
|
-
let key;
|
|
506
|
-
for (key in check) {
|
|
507
|
-
if (nodeAsRecord[key] !== checkAsRecord[key]) return false;
|
|
508
|
-
}
|
|
509
|
-
return true;
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
function typeFactory(check) {
|
|
513
|
-
return castFactory(type);
|
|
514
|
-
function type(node2) {
|
|
515
|
-
return node2 && node2.type === check;
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
function castFactory(testFunction) {
|
|
519
|
-
return check;
|
|
520
|
-
function check(value, index, parent) {
|
|
521
|
-
return Boolean(
|
|
522
|
-
looksLikeANode(value) && testFunction.call(
|
|
523
|
-
this,
|
|
524
|
-
value,
|
|
525
|
-
typeof index === "number" ? index : void 0,
|
|
526
|
-
parent || void 0
|
|
527
|
-
)
|
|
528
|
-
);
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
function ok() {
|
|
532
|
-
return true;
|
|
533
|
-
}
|
|
534
|
-
function looksLikeANode(value) {
|
|
535
|
-
return value !== null && typeof value === "object" && "type" in value;
|
|
536
|
-
}
|
|
537
|
-
function color(d) {
|
|
538
|
-
return d;
|
|
539
|
-
}
|
|
540
|
-
const empty = [];
|
|
541
|
-
const CONTINUE = true;
|
|
542
|
-
const EXIT = false;
|
|
543
|
-
const SKIP = "skip";
|
|
544
|
-
function visitParents(tree, test, visitor, reverse) {
|
|
545
|
-
let check;
|
|
546
|
-
if (typeof test === "function" && typeof visitor !== "function") {
|
|
547
|
-
reverse = visitor;
|
|
548
|
-
visitor = test;
|
|
549
|
-
} else {
|
|
550
|
-
check = test;
|
|
551
|
-
}
|
|
552
|
-
const is = convert(check);
|
|
553
|
-
const step = reverse ? -1 : 1;
|
|
554
|
-
factory(tree, void 0, [])();
|
|
555
|
-
function factory(node2, index, parents) {
|
|
556
|
-
const value = (
|
|
557
|
-
/** @type {Record<string, unknown>} */
|
|
558
|
-
node2 && typeof node2 === "object" ? node2 : {}
|
|
559
|
-
);
|
|
560
|
-
if (typeof value.type === "string") {
|
|
561
|
-
const name = (
|
|
562
|
-
// `hast`
|
|
563
|
-
typeof value.tagName === "string" ? value.tagName : (
|
|
564
|
-
// `xast`
|
|
565
|
-
typeof value.name === "string" ? value.name : void 0
|
|
566
|
-
)
|
|
567
|
-
);
|
|
568
|
-
Object.defineProperty(visit2, "name", {
|
|
569
|
-
value: "node (" + color(node2.type + (name ? "<" + name + ">" : "")) + ")"
|
|
570
|
-
});
|
|
571
|
-
}
|
|
572
|
-
return visit2;
|
|
573
|
-
function visit2() {
|
|
574
|
-
let result = empty;
|
|
575
|
-
let subresult;
|
|
576
|
-
let offset;
|
|
577
|
-
let grandparents;
|
|
578
|
-
if (!test || is(node2, index, parents[parents.length - 1] || void 0)) {
|
|
579
|
-
result = toResult(visitor(node2, parents));
|
|
580
|
-
if (result[0] === EXIT) {
|
|
581
|
-
return result;
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
if ("children" in node2 && node2.children) {
|
|
585
|
-
const nodeAsParent = (
|
|
586
|
-
/** @type {UnistParent} */
|
|
587
|
-
node2
|
|
588
|
-
);
|
|
589
|
-
if (nodeAsParent.children && result[0] !== SKIP) {
|
|
590
|
-
offset = (reverse ? nodeAsParent.children.length : -1) + step;
|
|
591
|
-
grandparents = parents.concat(nodeAsParent);
|
|
592
|
-
while (offset > -1 && offset < nodeAsParent.children.length) {
|
|
593
|
-
const child = nodeAsParent.children[offset];
|
|
594
|
-
subresult = factory(child, offset, grandparents)();
|
|
595
|
-
if (subresult[0] === EXIT) {
|
|
596
|
-
return subresult;
|
|
597
|
-
}
|
|
598
|
-
offset = typeof subresult[1] === "number" ? subresult[1] : offset + step;
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
return result;
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
function toResult(value) {
|
|
607
|
-
if (Array.isArray(value)) {
|
|
608
|
-
return value;
|
|
609
|
-
}
|
|
610
|
-
if (typeof value === "number") {
|
|
611
|
-
return [CONTINUE, value];
|
|
612
|
-
}
|
|
613
|
-
return value === null || value === void 0 ? empty : [value];
|
|
614
|
-
}
|
|
615
|
-
function findAndReplace(tree, list2, options) {
|
|
616
|
-
const settings = options || {};
|
|
617
|
-
const ignored = convert(settings.ignore || []);
|
|
618
|
-
const pairs = toPairs(list2);
|
|
619
|
-
let pairIndex = -1;
|
|
620
|
-
while (++pairIndex < pairs.length) {
|
|
621
|
-
visitParents(tree, "text", visitor);
|
|
622
|
-
}
|
|
623
|
-
function visitor(node2, parents) {
|
|
624
|
-
let index = -1;
|
|
625
|
-
let grandparent;
|
|
626
|
-
while (++index < parents.length) {
|
|
627
|
-
const parent = parents[index];
|
|
628
|
-
const siblings = grandparent ? grandparent.children : void 0;
|
|
629
|
-
if (ignored(
|
|
630
|
-
parent,
|
|
631
|
-
siblings ? siblings.indexOf(parent) : void 0,
|
|
632
|
-
grandparent
|
|
633
|
-
)) {
|
|
634
|
-
return;
|
|
635
|
-
}
|
|
636
|
-
grandparent = parent;
|
|
637
|
-
}
|
|
638
|
-
if (grandparent) {
|
|
639
|
-
return handler(node2, parents);
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
function handler(node2, parents) {
|
|
643
|
-
const parent = parents[parents.length - 1];
|
|
644
|
-
const find = pairs[pairIndex][0];
|
|
645
|
-
const replace2 = pairs[pairIndex][1];
|
|
646
|
-
let start = 0;
|
|
647
|
-
const siblings = parent.children;
|
|
648
|
-
const index = siblings.indexOf(node2);
|
|
649
|
-
let change = false;
|
|
650
|
-
let nodes = [];
|
|
651
|
-
find.lastIndex = 0;
|
|
652
|
-
let match = find.exec(node2.value);
|
|
653
|
-
while (match) {
|
|
654
|
-
const position = match.index;
|
|
655
|
-
const matchObject = {
|
|
656
|
-
index: match.index,
|
|
657
|
-
input: match.input,
|
|
658
|
-
stack: [...parents, node2]
|
|
659
|
-
};
|
|
660
|
-
let value = replace2(...match, matchObject);
|
|
661
|
-
if (typeof value === "string") {
|
|
662
|
-
value = value.length > 0 ? { type: "text", value } : void 0;
|
|
663
|
-
}
|
|
664
|
-
if (value === false) {
|
|
665
|
-
find.lastIndex = position + 1;
|
|
666
|
-
} else {
|
|
667
|
-
if (start !== position) {
|
|
668
|
-
nodes.push({
|
|
669
|
-
type: "text",
|
|
670
|
-
value: node2.value.slice(start, position)
|
|
671
|
-
});
|
|
672
|
-
}
|
|
673
|
-
if (Array.isArray(value)) {
|
|
674
|
-
nodes.push(...value);
|
|
675
|
-
} else if (value) {
|
|
676
|
-
nodes.push(value);
|
|
677
|
-
}
|
|
678
|
-
start = position + match[0].length;
|
|
679
|
-
change = true;
|
|
680
|
-
}
|
|
681
|
-
if (!find.global) {
|
|
682
|
-
break;
|
|
683
|
-
}
|
|
684
|
-
match = find.exec(node2.value);
|
|
685
|
-
}
|
|
686
|
-
if (change) {
|
|
687
|
-
if (start < node2.value.length) {
|
|
688
|
-
nodes.push({ type: "text", value: node2.value.slice(start) });
|
|
689
|
-
}
|
|
690
|
-
parent.children.splice(index, 1, ...nodes);
|
|
691
|
-
} else {
|
|
692
|
-
nodes = [node2];
|
|
693
|
-
}
|
|
694
|
-
return index + nodes.length;
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
function toPairs(tupleOrList) {
|
|
698
|
-
const result = [];
|
|
699
|
-
if (!Array.isArray(tupleOrList)) {
|
|
700
|
-
throw new TypeError("Expected find and replace tuple or list of tuples");
|
|
701
|
-
}
|
|
702
|
-
const list2 = !tupleOrList[0] || Array.isArray(tupleOrList[0]) ? tupleOrList : [tupleOrList];
|
|
703
|
-
let index = -1;
|
|
704
|
-
while (++index < list2.length) {
|
|
705
|
-
const tuple = list2[index];
|
|
706
|
-
result.push([toExpression(tuple[0]), toFunction(tuple[1])]);
|
|
707
|
-
}
|
|
708
|
-
return result;
|
|
709
|
-
}
|
|
710
|
-
function toExpression(find) {
|
|
711
|
-
return typeof find === "string" ? new RegExp(escapeStringRegexp(find), "g") : find;
|
|
712
|
-
}
|
|
713
|
-
function toFunction(replace2) {
|
|
714
|
-
return typeof replace2 === "function" ? replace2 : function() {
|
|
715
|
-
return replace2;
|
|
716
|
-
};
|
|
717
|
-
}
|
|
718
|
-
const inConstruct = "phrasing";
|
|
719
|
-
const notInConstruct = ["autolink", "link", "image", "label"];
|
|
720
|
-
function gfmAutolinkLiteralFromMarkdown() {
|
|
721
|
-
return {
|
|
722
|
-
transforms: [transformGfmAutolinkLiterals],
|
|
723
|
-
enter: {
|
|
724
|
-
literalAutolink: enterLiteralAutolink,
|
|
725
|
-
literalAutolinkEmail: enterLiteralAutolinkValue,
|
|
726
|
-
literalAutolinkHttp: enterLiteralAutolinkValue,
|
|
727
|
-
literalAutolinkWww: enterLiteralAutolinkValue
|
|
728
|
-
},
|
|
729
|
-
exit: {
|
|
730
|
-
literalAutolink: exitLiteralAutolink,
|
|
731
|
-
literalAutolinkEmail: exitLiteralAutolinkEmail,
|
|
732
|
-
literalAutolinkHttp: exitLiteralAutolinkHttp,
|
|
733
|
-
literalAutolinkWww: exitLiteralAutolinkWww
|
|
734
|
-
}
|
|
735
|
-
};
|
|
736
|
-
}
|
|
737
|
-
function gfmAutolinkLiteralToMarkdown() {
|
|
738
|
-
return {
|
|
739
|
-
unsafe: [
|
|
740
|
-
{
|
|
741
|
-
character: "@",
|
|
742
|
-
before: "[+\\-.\\w]",
|
|
743
|
-
after: "[\\-.\\w]",
|
|
744
|
-
inConstruct,
|
|
745
|
-
notInConstruct
|
|
746
|
-
},
|
|
747
|
-
{
|
|
748
|
-
character: ".",
|
|
749
|
-
before: "[Ww]",
|
|
750
|
-
after: "[\\-.\\w]",
|
|
751
|
-
inConstruct,
|
|
752
|
-
notInConstruct
|
|
753
|
-
},
|
|
754
|
-
{
|
|
755
|
-
character: ":",
|
|
756
|
-
before: "[ps]",
|
|
757
|
-
after: "\\/",
|
|
758
|
-
inConstruct,
|
|
759
|
-
notInConstruct
|
|
760
|
-
}
|
|
761
|
-
]
|
|
762
|
-
};
|
|
763
|
-
}
|
|
764
|
-
function enterLiteralAutolink(token) {
|
|
765
|
-
this.enter({ type: "link", title: null, url: "", children: [] }, token);
|
|
766
|
-
}
|
|
767
|
-
function enterLiteralAutolinkValue(token) {
|
|
768
|
-
this.config.enter.autolinkProtocol.call(this, token);
|
|
769
|
-
}
|
|
770
|
-
function exitLiteralAutolinkHttp(token) {
|
|
771
|
-
this.config.exit.autolinkProtocol.call(this, token);
|
|
772
|
-
}
|
|
773
|
-
function exitLiteralAutolinkWww(token) {
|
|
774
|
-
this.config.exit.data.call(this, token);
|
|
775
|
-
const node2 = this.stack[this.stack.length - 1];
|
|
776
|
-
ok$1(node2.type === "link");
|
|
777
|
-
node2.url = "http://" + this.sliceSerialize(token);
|
|
778
|
-
}
|
|
779
|
-
function exitLiteralAutolinkEmail(token) {
|
|
780
|
-
this.config.exit.autolinkEmail.call(this, token);
|
|
781
|
-
}
|
|
782
|
-
function exitLiteralAutolink(token) {
|
|
783
|
-
this.exit(token);
|
|
784
|
-
}
|
|
785
|
-
function transformGfmAutolinkLiterals(tree) {
|
|
786
|
-
findAndReplace(
|
|
787
|
-
tree,
|
|
788
|
-
[
|
|
789
|
-
[/(https?:\/\/|www(?=\.))([-.\w]+)([^ \t\r\n]*)/gi, findUrl],
|
|
790
|
-
[new RegExp("(?<=^|\\s|\\p{P}|\\p{S})([-.\\w+]+)@([-\\w]+(?:\\.[-\\w]+)+)", "gu"), findEmail]
|
|
791
|
-
],
|
|
792
|
-
{ ignore: ["link", "linkReference"] }
|
|
793
|
-
);
|
|
794
|
-
}
|
|
795
|
-
function findUrl(_, protocol, domain2, path2, match) {
|
|
796
|
-
let prefix = "";
|
|
797
|
-
if (!previous(match)) {
|
|
798
|
-
return false;
|
|
799
|
-
}
|
|
800
|
-
if (/^w/i.test(protocol)) {
|
|
801
|
-
domain2 = protocol + domain2;
|
|
802
|
-
protocol = "";
|
|
803
|
-
prefix = "http://";
|
|
804
|
-
}
|
|
805
|
-
if (!isCorrectDomain(domain2)) {
|
|
806
|
-
return false;
|
|
807
|
-
}
|
|
808
|
-
const parts = splitUrl(domain2 + path2);
|
|
809
|
-
if (!parts[0]) return false;
|
|
810
|
-
const result = {
|
|
811
|
-
type: "link",
|
|
812
|
-
title: null,
|
|
813
|
-
url: prefix + protocol + parts[0],
|
|
814
|
-
children: [{ type: "text", value: protocol + parts[0] }]
|
|
815
|
-
};
|
|
816
|
-
if (parts[1]) {
|
|
817
|
-
return [result, { type: "text", value: parts[1] }];
|
|
818
|
-
}
|
|
819
|
-
return result;
|
|
820
|
-
}
|
|
821
|
-
function findEmail(_, atext, label, match) {
|
|
822
|
-
if (
|
|
823
|
-
// Not an expected previous character.
|
|
824
|
-
!previous(match, true) || // Label ends in not allowed character.
|
|
825
|
-
/[-\d_]$/.test(label)
|
|
826
|
-
) {
|
|
827
|
-
return false;
|
|
828
|
-
}
|
|
829
|
-
return {
|
|
830
|
-
type: "link",
|
|
831
|
-
title: null,
|
|
832
|
-
url: "mailto:" + atext + "@" + label,
|
|
833
|
-
children: [{ type: "text", value: atext + "@" + label }]
|
|
834
|
-
};
|
|
835
|
-
}
|
|
836
|
-
function isCorrectDomain(domain2) {
|
|
837
|
-
const parts = domain2.split(".");
|
|
838
|
-
if (parts.length < 2 || parts[parts.length - 1] && (/_/.test(parts[parts.length - 1]) || !/[a-zA-Z\d]/.test(parts[parts.length - 1])) || parts[parts.length - 2] && (/_/.test(parts[parts.length - 2]) || !/[a-zA-Z\d]/.test(parts[parts.length - 2]))) {
|
|
839
|
-
return false;
|
|
840
|
-
}
|
|
841
|
-
return true;
|
|
842
|
-
}
|
|
843
|
-
function splitUrl(url) {
|
|
844
|
-
const trailExec = /[!"&'),.:;<>?\]}]+$/.exec(url);
|
|
845
|
-
if (!trailExec) {
|
|
846
|
-
return [url, void 0];
|
|
847
|
-
}
|
|
848
|
-
url = url.slice(0, trailExec.index);
|
|
849
|
-
let trail2 = trailExec[0];
|
|
850
|
-
let closingParenIndex = trail2.indexOf(")");
|
|
851
|
-
const openingParens = ccount(url, "(");
|
|
852
|
-
let closingParens = ccount(url, ")");
|
|
853
|
-
while (closingParenIndex !== -1 && openingParens > closingParens) {
|
|
854
|
-
url += trail2.slice(0, closingParenIndex + 1);
|
|
855
|
-
trail2 = trail2.slice(closingParenIndex + 1);
|
|
856
|
-
closingParenIndex = trail2.indexOf(")");
|
|
857
|
-
closingParens++;
|
|
858
|
-
}
|
|
859
|
-
return [url, trail2];
|
|
860
|
-
}
|
|
861
|
-
function previous(match, email) {
|
|
862
|
-
const code2 = match.input.charCodeAt(match.index - 1);
|
|
863
|
-
return (match.index === 0 || unicodeWhitespace(code2) || unicodePunctuation(code2)) && // If it’s an email, the previous character should not be a slash.
|
|
864
|
-
(!email || code2 !== 47);
|
|
865
|
-
}
|
|
866
|
-
function normalizeIdentifier(value) {
|
|
867
|
-
return value.replace(/[\t\n\r ]+/g, " ").replace(/^ | $/g, "").toLowerCase().toUpperCase();
|
|
868
|
-
}
|
|
869
|
-
footnoteReference.peek = footnoteReferencePeek;
|
|
870
|
-
function enterFootnoteCallString() {
|
|
871
|
-
this.buffer();
|
|
872
|
-
}
|
|
873
|
-
function enterFootnoteCall(token) {
|
|
874
|
-
this.enter({ type: "footnoteReference", identifier: "", label: "" }, token);
|
|
875
|
-
}
|
|
876
|
-
function enterFootnoteDefinitionLabelString() {
|
|
877
|
-
this.buffer();
|
|
878
|
-
}
|
|
879
|
-
function enterFootnoteDefinition(token) {
|
|
880
|
-
this.enter(
|
|
881
|
-
{ type: "footnoteDefinition", identifier: "", label: "", children: [] },
|
|
882
|
-
token
|
|
883
|
-
);
|
|
884
|
-
}
|
|
885
|
-
function exitFootnoteCallString(token) {
|
|
886
|
-
const label = this.resume();
|
|
887
|
-
const node2 = this.stack[this.stack.length - 1];
|
|
888
|
-
ok$1(node2.type === "footnoteReference");
|
|
889
|
-
node2.identifier = normalizeIdentifier(
|
|
890
|
-
this.sliceSerialize(token)
|
|
891
|
-
).toLowerCase();
|
|
892
|
-
node2.label = label;
|
|
893
|
-
}
|
|
894
|
-
function exitFootnoteCall(token) {
|
|
895
|
-
this.exit(token);
|
|
896
|
-
}
|
|
897
|
-
function exitFootnoteDefinitionLabelString(token) {
|
|
898
|
-
const label = this.resume();
|
|
899
|
-
const node2 = this.stack[this.stack.length - 1];
|
|
900
|
-
ok$1(node2.type === "footnoteDefinition");
|
|
901
|
-
node2.identifier = normalizeIdentifier(
|
|
902
|
-
this.sliceSerialize(token)
|
|
903
|
-
).toLowerCase();
|
|
904
|
-
node2.label = label;
|
|
905
|
-
}
|
|
906
|
-
function exitFootnoteDefinition(token) {
|
|
907
|
-
this.exit(token);
|
|
908
|
-
}
|
|
909
|
-
function footnoteReferencePeek() {
|
|
910
|
-
return "[";
|
|
911
|
-
}
|
|
912
|
-
function footnoteReference(node2, _, state, info) {
|
|
913
|
-
const tracker = state.createTracker(info);
|
|
914
|
-
let value = tracker.move("[^");
|
|
915
|
-
const exit2 = state.enter("footnoteReference");
|
|
916
|
-
const subexit = state.enter("reference");
|
|
917
|
-
value += tracker.move(
|
|
918
|
-
state.safe(state.associationId(node2), { after: "]", before: value })
|
|
919
|
-
);
|
|
920
|
-
subexit();
|
|
921
|
-
exit2();
|
|
922
|
-
value += tracker.move("]");
|
|
923
|
-
return value;
|
|
924
|
-
}
|
|
925
|
-
function gfmFootnoteFromMarkdown() {
|
|
926
|
-
return {
|
|
927
|
-
enter: {
|
|
928
|
-
gfmFootnoteCallString: enterFootnoteCallString,
|
|
929
|
-
gfmFootnoteCall: enterFootnoteCall,
|
|
930
|
-
gfmFootnoteDefinitionLabelString: enterFootnoteDefinitionLabelString,
|
|
931
|
-
gfmFootnoteDefinition: enterFootnoteDefinition
|
|
932
|
-
},
|
|
933
|
-
exit: {
|
|
934
|
-
gfmFootnoteCallString: exitFootnoteCallString,
|
|
935
|
-
gfmFootnoteCall: exitFootnoteCall,
|
|
936
|
-
gfmFootnoteDefinitionLabelString: exitFootnoteDefinitionLabelString,
|
|
937
|
-
gfmFootnoteDefinition: exitFootnoteDefinition
|
|
938
|
-
}
|
|
939
|
-
};
|
|
940
|
-
}
|
|
941
|
-
function gfmFootnoteToMarkdown(options) {
|
|
942
|
-
let firstLineBlank = false;
|
|
943
|
-
if (options && options.firstLineBlank) {
|
|
944
|
-
firstLineBlank = true;
|
|
945
|
-
}
|
|
946
|
-
return {
|
|
947
|
-
handlers: { footnoteDefinition, footnoteReference },
|
|
948
|
-
// This is on by default already.
|
|
949
|
-
unsafe: [{ character: "[", inConstruct: ["label", "phrasing", "reference"] }]
|
|
950
|
-
};
|
|
951
|
-
function footnoteDefinition(node2, _, state, info) {
|
|
952
|
-
const tracker = state.createTracker(info);
|
|
953
|
-
let value = tracker.move("[^");
|
|
954
|
-
const exit2 = state.enter("footnoteDefinition");
|
|
955
|
-
const subexit = state.enter("label");
|
|
956
|
-
value += tracker.move(
|
|
957
|
-
state.safe(state.associationId(node2), { before: value, after: "]" })
|
|
958
|
-
);
|
|
959
|
-
subexit();
|
|
960
|
-
value += tracker.move("]:");
|
|
961
|
-
if (node2.children && node2.children.length > 0) {
|
|
962
|
-
tracker.shift(4);
|
|
963
|
-
value += tracker.move(
|
|
964
|
-
(firstLineBlank ? "\n" : " ") + state.indentLines(
|
|
965
|
-
state.containerFlow(node2, tracker.current()),
|
|
966
|
-
firstLineBlank ? mapAll : mapExceptFirst
|
|
967
|
-
)
|
|
968
|
-
);
|
|
969
|
-
}
|
|
970
|
-
exit2();
|
|
971
|
-
return value;
|
|
972
|
-
}
|
|
973
|
-
}
|
|
974
|
-
function mapExceptFirst(line, index, blank) {
|
|
975
|
-
return index === 0 ? line : mapAll(line, index, blank);
|
|
976
|
-
}
|
|
977
|
-
function mapAll(line, index, blank) {
|
|
978
|
-
return (blank ? "" : " ") + line;
|
|
979
|
-
}
|
|
980
|
-
const constructsWithoutStrikethrough = [
|
|
981
|
-
"autolink",
|
|
982
|
-
"destinationLiteral",
|
|
983
|
-
"destinationRaw",
|
|
984
|
-
"reference",
|
|
985
|
-
"titleQuote",
|
|
986
|
-
"titleApostrophe"
|
|
987
|
-
];
|
|
988
|
-
handleDelete.peek = peekDelete;
|
|
989
|
-
function gfmStrikethroughFromMarkdown() {
|
|
990
|
-
return {
|
|
991
|
-
canContainEols: ["delete"],
|
|
992
|
-
enter: { strikethrough: enterStrikethrough },
|
|
993
|
-
exit: { strikethrough: exitStrikethrough }
|
|
994
|
-
};
|
|
995
|
-
}
|
|
996
|
-
function gfmStrikethroughToMarkdown() {
|
|
997
|
-
return {
|
|
998
|
-
unsafe: [
|
|
999
|
-
{
|
|
1000
|
-
character: "~",
|
|
1001
|
-
inConstruct: "phrasing",
|
|
1002
|
-
notInConstruct: constructsWithoutStrikethrough
|
|
1003
|
-
}
|
|
1004
|
-
],
|
|
1005
|
-
handlers: { delete: handleDelete }
|
|
1006
|
-
};
|
|
1007
|
-
}
|
|
1008
|
-
function enterStrikethrough(token) {
|
|
1009
|
-
this.enter({ type: "delete", children: [] }, token);
|
|
1010
|
-
}
|
|
1011
|
-
function exitStrikethrough(token) {
|
|
1012
|
-
this.exit(token);
|
|
1013
|
-
}
|
|
1014
|
-
function handleDelete(node2, _, state, info) {
|
|
1015
|
-
const tracker = state.createTracker(info);
|
|
1016
|
-
const exit2 = state.enter("strikethrough");
|
|
1017
|
-
let value = tracker.move("~~");
|
|
1018
|
-
value += state.containerPhrasing(node2, {
|
|
1019
|
-
...tracker.current(),
|
|
1020
|
-
before: value,
|
|
1021
|
-
after: "~"
|
|
1022
|
-
});
|
|
1023
|
-
value += tracker.move("~~");
|
|
1024
|
-
exit2();
|
|
1025
|
-
return value;
|
|
1026
|
-
}
|
|
1027
|
-
function peekDelete() {
|
|
1028
|
-
return "~";
|
|
1029
|
-
}
|
|
1030
|
-
function defaultStringLength(value) {
|
|
1031
|
-
return value.length;
|
|
1032
|
-
}
|
|
1033
|
-
function markdownTable(table, options) {
|
|
1034
|
-
const settings = options || {};
|
|
1035
|
-
const align = (settings.align || []).concat();
|
|
1036
|
-
const stringLength = settings.stringLength || defaultStringLength;
|
|
1037
|
-
const alignments = [];
|
|
1038
|
-
const cellMatrix = [];
|
|
1039
|
-
const sizeMatrix = [];
|
|
1040
|
-
const longestCellByColumn = [];
|
|
1041
|
-
let mostCellsPerRow = 0;
|
|
1042
|
-
let rowIndex = -1;
|
|
1043
|
-
while (++rowIndex < table.length) {
|
|
1044
|
-
const row2 = [];
|
|
1045
|
-
const sizes2 = [];
|
|
1046
|
-
let columnIndex2 = -1;
|
|
1047
|
-
if (table[rowIndex].length > mostCellsPerRow) {
|
|
1048
|
-
mostCellsPerRow = table[rowIndex].length;
|
|
1049
|
-
}
|
|
1050
|
-
while (++columnIndex2 < table[rowIndex].length) {
|
|
1051
|
-
const cell = serialize(table[rowIndex][columnIndex2]);
|
|
1052
|
-
if (settings.alignDelimiters !== false) {
|
|
1053
|
-
const size = stringLength(cell);
|
|
1054
|
-
sizes2[columnIndex2] = size;
|
|
1055
|
-
if (longestCellByColumn[columnIndex2] === void 0 || size > longestCellByColumn[columnIndex2]) {
|
|
1056
|
-
longestCellByColumn[columnIndex2] = size;
|
|
1057
|
-
}
|
|
1058
|
-
}
|
|
1059
|
-
row2.push(cell);
|
|
1060
|
-
}
|
|
1061
|
-
cellMatrix[rowIndex] = row2;
|
|
1062
|
-
sizeMatrix[rowIndex] = sizes2;
|
|
1063
|
-
}
|
|
1064
|
-
let columnIndex = -1;
|
|
1065
|
-
if (typeof align === "object" && "length" in align) {
|
|
1066
|
-
while (++columnIndex < mostCellsPerRow) {
|
|
1067
|
-
alignments[columnIndex] = toAlignment(align[columnIndex]);
|
|
1068
|
-
}
|
|
1069
|
-
} else {
|
|
1070
|
-
const code2 = toAlignment(align);
|
|
1071
|
-
while (++columnIndex < mostCellsPerRow) {
|
|
1072
|
-
alignments[columnIndex] = code2;
|
|
1073
|
-
}
|
|
1074
|
-
}
|
|
1075
|
-
columnIndex = -1;
|
|
1076
|
-
const row = [];
|
|
1077
|
-
const sizes = [];
|
|
1078
|
-
while (++columnIndex < mostCellsPerRow) {
|
|
1079
|
-
const code2 = alignments[columnIndex];
|
|
1080
|
-
let before = "";
|
|
1081
|
-
let after = "";
|
|
1082
|
-
if (code2 === 99) {
|
|
1083
|
-
before = ":";
|
|
1084
|
-
after = ":";
|
|
1085
|
-
} else if (code2 === 108) {
|
|
1086
|
-
before = ":";
|
|
1087
|
-
} else if (code2 === 114) {
|
|
1088
|
-
after = ":";
|
|
1089
|
-
}
|
|
1090
|
-
let size = settings.alignDelimiters === false ? 1 : Math.max(
|
|
1091
|
-
1,
|
|
1092
|
-
longestCellByColumn[columnIndex] - before.length - after.length
|
|
1093
|
-
);
|
|
1094
|
-
const cell = before + "-".repeat(size) + after;
|
|
1095
|
-
if (settings.alignDelimiters !== false) {
|
|
1096
|
-
size = before.length + size + after.length;
|
|
1097
|
-
if (size > longestCellByColumn[columnIndex]) {
|
|
1098
|
-
longestCellByColumn[columnIndex] = size;
|
|
1099
|
-
}
|
|
1100
|
-
sizes[columnIndex] = size;
|
|
1101
|
-
}
|
|
1102
|
-
row[columnIndex] = cell;
|
|
1103
|
-
}
|
|
1104
|
-
cellMatrix.splice(1, 0, row);
|
|
1105
|
-
sizeMatrix.splice(1, 0, sizes);
|
|
1106
|
-
rowIndex = -1;
|
|
1107
|
-
const lines = [];
|
|
1108
|
-
while (++rowIndex < cellMatrix.length) {
|
|
1109
|
-
const row2 = cellMatrix[rowIndex];
|
|
1110
|
-
const sizes2 = sizeMatrix[rowIndex];
|
|
1111
|
-
columnIndex = -1;
|
|
1112
|
-
const line = [];
|
|
1113
|
-
while (++columnIndex < mostCellsPerRow) {
|
|
1114
|
-
const cell = row2[columnIndex] || "";
|
|
1115
|
-
let before = "";
|
|
1116
|
-
let after = "";
|
|
1117
|
-
if (settings.alignDelimiters !== false) {
|
|
1118
|
-
const size = longestCellByColumn[columnIndex] - (sizes2[columnIndex] || 0);
|
|
1119
|
-
const code2 = alignments[columnIndex];
|
|
1120
|
-
if (code2 === 114) {
|
|
1121
|
-
before = " ".repeat(size);
|
|
1122
|
-
} else if (code2 === 99) {
|
|
1123
|
-
if (size % 2) {
|
|
1124
|
-
before = " ".repeat(size / 2 + 0.5);
|
|
1125
|
-
after = " ".repeat(size / 2 - 0.5);
|
|
1126
|
-
} else {
|
|
1127
|
-
before = " ".repeat(size / 2);
|
|
1128
|
-
after = before;
|
|
1129
|
-
}
|
|
1130
|
-
} else {
|
|
1131
|
-
after = " ".repeat(size);
|
|
1132
|
-
}
|
|
1133
|
-
}
|
|
1134
|
-
if (settings.delimiterStart !== false && !columnIndex) {
|
|
1135
|
-
line.push("|");
|
|
1136
|
-
}
|
|
1137
|
-
if (settings.padding !== false && // Don’t add the opening space if we’re not aligning and the cell is
|
|
1138
|
-
// empty: there will be a closing space.
|
|
1139
|
-
!(settings.alignDelimiters === false && cell === "") && (settings.delimiterStart !== false || columnIndex)) {
|
|
1140
|
-
line.push(" ");
|
|
1141
|
-
}
|
|
1142
|
-
if (settings.alignDelimiters !== false) {
|
|
1143
|
-
line.push(before);
|
|
1144
|
-
}
|
|
1145
|
-
line.push(cell);
|
|
1146
|
-
if (settings.alignDelimiters !== false) {
|
|
1147
|
-
line.push(after);
|
|
1148
|
-
}
|
|
1149
|
-
if (settings.padding !== false) {
|
|
1150
|
-
line.push(" ");
|
|
1151
|
-
}
|
|
1152
|
-
if (settings.delimiterEnd !== false || columnIndex !== mostCellsPerRow - 1) {
|
|
1153
|
-
line.push("|");
|
|
1154
|
-
}
|
|
1155
|
-
}
|
|
1156
|
-
lines.push(
|
|
1157
|
-
settings.delimiterEnd === false ? line.join("").replace(/ +$/, "") : line.join("")
|
|
1158
|
-
);
|
|
1159
|
-
}
|
|
1160
|
-
return lines.join("\n");
|
|
1161
|
-
}
|
|
1162
|
-
function serialize(value) {
|
|
1163
|
-
return value === null || value === void 0 ? "" : String(value);
|
|
1164
|
-
}
|
|
1165
|
-
function toAlignment(value) {
|
|
1166
|
-
const code2 = typeof value === "string" ? value.codePointAt(0) : 0;
|
|
1167
|
-
return code2 === 67 || code2 === 99 ? 99 : code2 === 76 || code2 === 108 ? 108 : code2 === 82 || code2 === 114 ? 114 : 0;
|
|
1168
|
-
}
|
|
1169
|
-
function blockquote(node2, _, state, info) {
|
|
1170
|
-
const exit2 = state.enter("blockquote");
|
|
1171
|
-
const tracker = state.createTracker(info);
|
|
1172
|
-
tracker.move("> ");
|
|
1173
|
-
tracker.shift(2);
|
|
1174
|
-
const value = state.indentLines(
|
|
1175
|
-
state.containerFlow(node2, tracker.current()),
|
|
1176
|
-
map$1
|
|
1177
|
-
);
|
|
1178
|
-
exit2();
|
|
1179
|
-
return value;
|
|
1180
|
-
}
|
|
1181
|
-
function map$1(line, _, blank) {
|
|
1182
|
-
return ">" + (blank ? "" : " ") + line;
|
|
1183
|
-
}
|
|
1184
|
-
function patternInScope(stack, pattern) {
|
|
1185
|
-
return listInScope(stack, pattern.inConstruct, true) && !listInScope(stack, pattern.notInConstruct, false);
|
|
1186
|
-
}
|
|
1187
|
-
function listInScope(stack, list2, none) {
|
|
1188
|
-
if (typeof list2 === "string") {
|
|
1189
|
-
list2 = [list2];
|
|
1190
|
-
}
|
|
1191
|
-
if (!list2 || list2.length === 0) {
|
|
1192
|
-
return none;
|
|
1193
|
-
}
|
|
1194
|
-
let index = -1;
|
|
1195
|
-
while (++index < list2.length) {
|
|
1196
|
-
if (stack.includes(list2[index])) {
|
|
1197
|
-
return true;
|
|
1198
|
-
}
|
|
1199
|
-
}
|
|
1200
|
-
return false;
|
|
1201
|
-
}
|
|
1202
|
-
function hardBreak(_, _1, state, info) {
|
|
1203
|
-
let index = -1;
|
|
1204
|
-
while (++index < state.unsafe.length) {
|
|
1205
|
-
if (state.unsafe[index].character === "\n" && patternInScope(state.stack, state.unsafe[index])) {
|
|
1206
|
-
return /[ \t]/.test(info.before) ? "" : " ";
|
|
1207
|
-
}
|
|
1208
|
-
}
|
|
1209
|
-
return "\\\n";
|
|
1210
|
-
}
|
|
1211
|
-
function longestStreak(value, substring) {
|
|
1212
|
-
const source = String(value);
|
|
1213
|
-
let index = source.indexOf(substring);
|
|
1214
|
-
let expected = index;
|
|
1215
|
-
let count = 0;
|
|
1216
|
-
let max = 0;
|
|
1217
|
-
if (typeof substring !== "string") {
|
|
1218
|
-
throw new TypeError("Expected substring");
|
|
1219
|
-
}
|
|
1220
|
-
while (index !== -1) {
|
|
1221
|
-
if (index === expected) {
|
|
1222
|
-
if (++count > max) {
|
|
1223
|
-
max = count;
|
|
1224
|
-
}
|
|
1225
|
-
} else {
|
|
1226
|
-
count = 1;
|
|
1227
|
-
}
|
|
1228
|
-
expected = index + substring.length;
|
|
1229
|
-
index = source.indexOf(substring, expected);
|
|
1230
|
-
}
|
|
1231
|
-
return max;
|
|
1232
|
-
}
|
|
1233
|
-
function formatCodeAsIndented(node2, state) {
|
|
1234
|
-
return Boolean(
|
|
1235
|
-
state.options.fences === false && node2.value && // If there’s no info…
|
|
1236
|
-
!node2.lang && // And there’s a non-whitespace character…
|
|
1237
|
-
/[^ \r\n]/.test(node2.value) && // And the value doesn’t start or end in a blank…
|
|
1238
|
-
!/^[\t ]*(?:[\r\n]|$)|(?:^|[\r\n])[\t ]*$/.test(node2.value)
|
|
1239
|
-
);
|
|
1240
|
-
}
|
|
1241
|
-
function checkFence(state) {
|
|
1242
|
-
const marker = state.options.fence || "`";
|
|
1243
|
-
if (marker !== "`" && marker !== "~") {
|
|
1244
|
-
throw new Error(
|
|
1245
|
-
"Cannot serialize code with `" + marker + "` for `options.fence`, expected `` ` `` or `~`"
|
|
1246
|
-
);
|
|
1247
|
-
}
|
|
1248
|
-
return marker;
|
|
1249
|
-
}
|
|
1250
|
-
function code$1(node2, _, state, info) {
|
|
1251
|
-
const marker = checkFence(state);
|
|
1252
|
-
const raw = node2.value || "";
|
|
1253
|
-
const suffix = marker === "`" ? "GraveAccent" : "Tilde";
|
|
1254
|
-
if (formatCodeAsIndented(node2, state)) {
|
|
1255
|
-
const exit3 = state.enter("codeIndented");
|
|
1256
|
-
const value2 = state.indentLines(raw, map);
|
|
1257
|
-
exit3();
|
|
1258
|
-
return value2;
|
|
1259
|
-
}
|
|
1260
|
-
const tracker = state.createTracker(info);
|
|
1261
|
-
const sequence = marker.repeat(Math.max(longestStreak(raw, marker) + 1, 3));
|
|
1262
|
-
const exit2 = state.enter("codeFenced");
|
|
1263
|
-
let value = tracker.move(sequence);
|
|
1264
|
-
if (node2.lang) {
|
|
1265
|
-
const subexit = state.enter(`codeFencedLang${suffix}`);
|
|
1266
|
-
value += tracker.move(
|
|
1267
|
-
state.safe(node2.lang, {
|
|
1268
|
-
before: value,
|
|
1269
|
-
after: " ",
|
|
1270
|
-
encode: ["`"],
|
|
1271
|
-
...tracker.current()
|
|
1272
|
-
})
|
|
1273
|
-
);
|
|
1274
|
-
subexit();
|
|
1275
|
-
}
|
|
1276
|
-
if (node2.lang && node2.meta) {
|
|
1277
|
-
const subexit = state.enter(`codeFencedMeta${suffix}`);
|
|
1278
|
-
value += tracker.move(" ");
|
|
1279
|
-
value += tracker.move(
|
|
1280
|
-
state.safe(node2.meta, {
|
|
1281
|
-
before: value,
|
|
1282
|
-
after: "\n",
|
|
1283
|
-
encode: ["`"],
|
|
1284
|
-
...tracker.current()
|
|
1285
|
-
})
|
|
1286
|
-
);
|
|
1287
|
-
subexit();
|
|
1288
|
-
}
|
|
1289
|
-
value += tracker.move("\n");
|
|
1290
|
-
if (raw) {
|
|
1291
|
-
value += tracker.move(raw + "\n");
|
|
1292
|
-
}
|
|
1293
|
-
value += tracker.move(sequence);
|
|
1294
|
-
exit2();
|
|
1295
|
-
return value;
|
|
1296
|
-
}
|
|
1297
|
-
function map(line, _, blank) {
|
|
1298
|
-
return (blank ? "" : " ") + line;
|
|
1299
|
-
}
|
|
1300
|
-
function checkQuote(state) {
|
|
1301
|
-
const marker = state.options.quote || '"';
|
|
1302
|
-
if (marker !== '"' && marker !== "'") {
|
|
1303
|
-
throw new Error(
|
|
1304
|
-
"Cannot serialize title with `" + marker + "` for `options.quote`, expected `\"`, or `'`"
|
|
1305
|
-
);
|
|
1306
|
-
}
|
|
1307
|
-
return marker;
|
|
1308
|
-
}
|
|
1309
|
-
function definition(node2, _, state, info) {
|
|
1310
|
-
const quote = checkQuote(state);
|
|
1311
|
-
const suffix = quote === '"' ? "Quote" : "Apostrophe";
|
|
1312
|
-
const exit2 = state.enter("definition");
|
|
1313
|
-
let subexit = state.enter("label");
|
|
1314
|
-
const tracker = state.createTracker(info);
|
|
1315
|
-
let value = tracker.move("[");
|
|
1316
|
-
value += tracker.move(
|
|
1317
|
-
state.safe(state.associationId(node2), {
|
|
1318
|
-
before: value,
|
|
1319
|
-
after: "]",
|
|
1320
|
-
...tracker.current()
|
|
1321
|
-
})
|
|
1322
|
-
);
|
|
1323
|
-
value += tracker.move("]: ");
|
|
1324
|
-
subexit();
|
|
1325
|
-
if (
|
|
1326
|
-
// If there’s no url, or…
|
|
1327
|
-
!node2.url || // If there are control characters or whitespace.
|
|
1328
|
-
/[\0- \u007F]/.test(node2.url)
|
|
1329
|
-
) {
|
|
1330
|
-
subexit = state.enter("destinationLiteral");
|
|
1331
|
-
value += tracker.move("<");
|
|
1332
|
-
value += tracker.move(
|
|
1333
|
-
state.safe(node2.url, { before: value, after: ">", ...tracker.current() })
|
|
1334
|
-
);
|
|
1335
|
-
value += tracker.move(">");
|
|
1336
|
-
} else {
|
|
1337
|
-
subexit = state.enter("destinationRaw");
|
|
1338
|
-
value += tracker.move(
|
|
1339
|
-
state.safe(node2.url, {
|
|
1340
|
-
before: value,
|
|
1341
|
-
after: node2.title ? " " : "\n",
|
|
1342
|
-
...tracker.current()
|
|
1343
|
-
})
|
|
1344
|
-
);
|
|
1345
|
-
}
|
|
1346
|
-
subexit();
|
|
1347
|
-
if (node2.title) {
|
|
1348
|
-
subexit = state.enter(`title${suffix}`);
|
|
1349
|
-
value += tracker.move(" " + quote);
|
|
1350
|
-
value += tracker.move(
|
|
1351
|
-
state.safe(node2.title, {
|
|
1352
|
-
before: value,
|
|
1353
|
-
after: quote,
|
|
1354
|
-
...tracker.current()
|
|
1355
|
-
})
|
|
1356
|
-
);
|
|
1357
|
-
value += tracker.move(quote);
|
|
1358
|
-
subexit();
|
|
1359
|
-
}
|
|
1360
|
-
exit2();
|
|
1361
|
-
return value;
|
|
1362
|
-
}
|
|
1363
|
-
function checkEmphasis(state) {
|
|
1364
|
-
const marker = state.options.emphasis || "*";
|
|
1365
|
-
if (marker !== "*" && marker !== "_") {
|
|
1366
|
-
throw new Error(
|
|
1367
|
-
"Cannot serialize emphasis with `" + marker + "` for `options.emphasis`, expected `*`, or `_`"
|
|
1368
|
-
);
|
|
1369
|
-
}
|
|
1370
|
-
return marker;
|
|
1371
|
-
}
|
|
1372
|
-
function encodeCharacterReference(code2) {
|
|
1373
|
-
return "&#x" + code2.toString(16).toUpperCase() + ";";
|
|
1374
|
-
}
|
|
1375
|
-
function classifyCharacter(code2) {
|
|
1376
|
-
if (code2 === null || markdownLineEndingOrSpace(code2) || unicodeWhitespace(code2)) {
|
|
1377
|
-
return 1;
|
|
1378
|
-
}
|
|
1379
|
-
if (unicodePunctuation(code2)) {
|
|
1380
|
-
return 2;
|
|
1381
|
-
}
|
|
1382
|
-
}
|
|
1383
|
-
function encodeInfo(outside, inside, marker) {
|
|
1384
|
-
const outsideKind = classifyCharacter(outside);
|
|
1385
|
-
const insideKind = classifyCharacter(inside);
|
|
1386
|
-
if (outsideKind === void 0) {
|
|
1387
|
-
return insideKind === void 0 ? (
|
|
1388
|
-
// Letter inside:
|
|
1389
|
-
// we have to encode *both* letters for `_` as it is looser.
|
|
1390
|
-
// it already forms for `*` (and GFMs `~`).
|
|
1391
|
-
marker === "_" ? { inside: true, outside: true } : { inside: false, outside: false }
|
|
1392
|
-
) : insideKind === 1 ? (
|
|
1393
|
-
// Whitespace inside: encode both (letter, whitespace).
|
|
1394
|
-
{ inside: true, outside: true }
|
|
1395
|
-
) : (
|
|
1396
|
-
// Punctuation inside: encode outer (letter)
|
|
1397
|
-
{ inside: false, outside: true }
|
|
1398
|
-
);
|
|
1399
|
-
}
|
|
1400
|
-
if (outsideKind === 1) {
|
|
1401
|
-
return insideKind === void 0 ? (
|
|
1402
|
-
// Letter inside: already forms.
|
|
1403
|
-
{ inside: false, outside: false }
|
|
1404
|
-
) : insideKind === 1 ? (
|
|
1405
|
-
// Whitespace inside: encode both (whitespace).
|
|
1406
|
-
{ inside: true, outside: true }
|
|
1407
|
-
) : (
|
|
1408
|
-
// Punctuation inside: already forms.
|
|
1409
|
-
{ inside: false, outside: false }
|
|
1410
|
-
);
|
|
1411
|
-
}
|
|
1412
|
-
return insideKind === void 0 ? (
|
|
1413
|
-
// Letter inside: already forms.
|
|
1414
|
-
{ inside: false, outside: false }
|
|
1415
|
-
) : insideKind === 1 ? (
|
|
1416
|
-
// Whitespace inside: encode inner (whitespace).
|
|
1417
|
-
{ inside: true, outside: false }
|
|
1418
|
-
) : (
|
|
1419
|
-
// Punctuation inside: already forms.
|
|
1420
|
-
{ inside: false, outside: false }
|
|
1421
|
-
);
|
|
1422
|
-
}
|
|
1423
|
-
emphasis.peek = emphasisPeek;
|
|
1424
|
-
function emphasis(node2, _, state, info) {
|
|
1425
|
-
const marker = checkEmphasis(state);
|
|
1426
|
-
const exit2 = state.enter("emphasis");
|
|
1427
|
-
const tracker = state.createTracker(info);
|
|
1428
|
-
const before = tracker.move(marker);
|
|
1429
|
-
let between = tracker.move(
|
|
1430
|
-
state.containerPhrasing(node2, {
|
|
1431
|
-
after: marker,
|
|
1432
|
-
before,
|
|
1433
|
-
...tracker.current()
|
|
1434
|
-
})
|
|
1435
|
-
);
|
|
1436
|
-
const betweenHead = between.charCodeAt(0);
|
|
1437
|
-
const open = encodeInfo(
|
|
1438
|
-
info.before.charCodeAt(info.before.length - 1),
|
|
1439
|
-
betweenHead,
|
|
1440
|
-
marker
|
|
1441
|
-
);
|
|
1442
|
-
if (open.inside) {
|
|
1443
|
-
between = encodeCharacterReference(betweenHead) + between.slice(1);
|
|
1444
|
-
}
|
|
1445
|
-
const betweenTail = between.charCodeAt(between.length - 1);
|
|
1446
|
-
const close = encodeInfo(info.after.charCodeAt(0), betweenTail, marker);
|
|
1447
|
-
if (close.inside) {
|
|
1448
|
-
between = between.slice(0, -1) + encodeCharacterReference(betweenTail);
|
|
1449
|
-
}
|
|
1450
|
-
const after = tracker.move(marker);
|
|
1451
|
-
exit2();
|
|
1452
|
-
state.attentionEncodeSurroundingInfo = {
|
|
1453
|
-
after: close.outside,
|
|
1454
|
-
before: open.outside
|
|
1455
|
-
};
|
|
1456
|
-
return before + between + after;
|
|
1457
|
-
}
|
|
1458
|
-
function emphasisPeek(_, _1, state) {
|
|
1459
|
-
return state.options.emphasis || "*";
|
|
1460
|
-
}
|
|
1461
|
-
function visit(tree, testOrVisitor, visitorOrReverse, maybeReverse) {
|
|
1462
|
-
let reverse;
|
|
1463
|
-
let test;
|
|
1464
|
-
let visitor;
|
|
1465
|
-
if (typeof testOrVisitor === "function" && typeof visitorOrReverse !== "function") {
|
|
1466
|
-
test = void 0;
|
|
1467
|
-
visitor = testOrVisitor;
|
|
1468
|
-
reverse = visitorOrReverse;
|
|
1469
|
-
} else {
|
|
1470
|
-
test = testOrVisitor;
|
|
1471
|
-
visitor = visitorOrReverse;
|
|
1472
|
-
reverse = maybeReverse;
|
|
1473
|
-
}
|
|
1474
|
-
visitParents(tree, test, overload, reverse);
|
|
1475
|
-
function overload(node2, parents) {
|
|
1476
|
-
const parent = parents[parents.length - 1];
|
|
1477
|
-
const index = parent ? parent.children.indexOf(node2) : void 0;
|
|
1478
|
-
return visitor(node2, index, parent);
|
|
1479
|
-
}
|
|
1480
|
-
}
|
|
1481
|
-
const emptyOptions$1 = {};
|
|
1482
|
-
function toString(value, options) {
|
|
1483
|
-
const settings = emptyOptions$1;
|
|
1484
|
-
const includeImageAlt = typeof settings.includeImageAlt === "boolean" ? settings.includeImageAlt : true;
|
|
1485
|
-
const includeHtml = typeof settings.includeHtml === "boolean" ? settings.includeHtml : true;
|
|
1486
|
-
return one(value, includeImageAlt, includeHtml);
|
|
1487
|
-
}
|
|
1488
|
-
function one(value, includeImageAlt, includeHtml) {
|
|
1489
|
-
if (node(value)) {
|
|
1490
|
-
if ("value" in value) {
|
|
1491
|
-
return value.type === "html" && !includeHtml ? "" : value.value;
|
|
1492
|
-
}
|
|
1493
|
-
if (includeImageAlt && "alt" in value && value.alt) {
|
|
1494
|
-
return value.alt;
|
|
1495
|
-
}
|
|
1496
|
-
if ("children" in value) {
|
|
1497
|
-
return all(value.children, includeImageAlt, includeHtml);
|
|
1498
|
-
}
|
|
1499
|
-
}
|
|
1500
|
-
if (Array.isArray(value)) {
|
|
1501
|
-
return all(value, includeImageAlt, includeHtml);
|
|
1502
|
-
}
|
|
1503
|
-
return "";
|
|
1504
|
-
}
|
|
1505
|
-
function all(values, includeImageAlt, includeHtml) {
|
|
1506
|
-
const result = [];
|
|
1507
|
-
let index = -1;
|
|
1508
|
-
while (++index < values.length) {
|
|
1509
|
-
result[index] = one(values[index], includeImageAlt, includeHtml);
|
|
1510
|
-
}
|
|
1511
|
-
return result.join("");
|
|
1512
|
-
}
|
|
1513
|
-
function node(value) {
|
|
1514
|
-
return Boolean(value && typeof value === "object");
|
|
1515
|
-
}
|
|
1516
|
-
function formatHeadingAsSetext(node2, state) {
|
|
1517
|
-
let literalWithBreak = false;
|
|
1518
|
-
visit(node2, function(node3) {
|
|
1519
|
-
if ("value" in node3 && /\r?\n|\r/.test(node3.value) || node3.type === "break") {
|
|
1520
|
-
literalWithBreak = true;
|
|
1521
|
-
return EXIT;
|
|
1522
|
-
}
|
|
1523
|
-
});
|
|
1524
|
-
return Boolean(
|
|
1525
|
-
(!node2.depth || node2.depth < 3) && toString(node2) && (state.options.setext || literalWithBreak)
|
|
1526
|
-
);
|
|
1527
|
-
}
|
|
1528
|
-
function heading(node2, _, state, info) {
|
|
1529
|
-
const rank = Math.max(Math.min(6, node2.depth || 1), 1);
|
|
1530
|
-
const tracker = state.createTracker(info);
|
|
1531
|
-
if (formatHeadingAsSetext(node2, state)) {
|
|
1532
|
-
const exit3 = state.enter("headingSetext");
|
|
1533
|
-
const subexit2 = state.enter("phrasing");
|
|
1534
|
-
const value2 = state.containerPhrasing(node2, {
|
|
1535
|
-
...tracker.current(),
|
|
1536
|
-
before: "\n",
|
|
1537
|
-
after: "\n"
|
|
1538
|
-
});
|
|
1539
|
-
subexit2();
|
|
1540
|
-
exit3();
|
|
1541
|
-
return value2 + "\n" + (rank === 1 ? "=" : "-").repeat(
|
|
1542
|
-
// The whole size…
|
|
1543
|
-
value2.length - // Minus the position of the character after the last EOL (or
|
|
1544
|
-
// 0 if there is none)…
|
|
1545
|
-
(Math.max(value2.lastIndexOf("\r"), value2.lastIndexOf("\n")) + 1)
|
|
1546
|
-
);
|
|
1547
|
-
}
|
|
1548
|
-
const sequence = "#".repeat(rank);
|
|
1549
|
-
const exit2 = state.enter("headingAtx");
|
|
1550
|
-
const subexit = state.enter("phrasing");
|
|
1551
|
-
tracker.move(sequence + " ");
|
|
1552
|
-
let value = state.containerPhrasing(node2, {
|
|
1553
|
-
before: "# ",
|
|
1554
|
-
after: "\n",
|
|
1555
|
-
...tracker.current()
|
|
1556
|
-
});
|
|
1557
|
-
if (/^[\t ]/.test(value)) {
|
|
1558
|
-
value = encodeCharacterReference(value.charCodeAt(0)) + value.slice(1);
|
|
1559
|
-
}
|
|
1560
|
-
value = value ? sequence + " " + value : sequence;
|
|
1561
|
-
if (state.options.closeAtx) {
|
|
1562
|
-
value += " " + sequence;
|
|
1563
|
-
}
|
|
1564
|
-
subexit();
|
|
1565
|
-
exit2();
|
|
1566
|
-
return value;
|
|
1567
|
-
}
|
|
1568
|
-
html.peek = htmlPeek;
|
|
1569
|
-
function html(node2) {
|
|
1570
|
-
return node2.value || "";
|
|
1571
|
-
}
|
|
1572
|
-
function htmlPeek() {
|
|
1573
|
-
return "<";
|
|
1574
|
-
}
|
|
1575
|
-
image.peek = imagePeek;
|
|
1576
|
-
function image(node2, _, state, info) {
|
|
1577
|
-
const quote = checkQuote(state);
|
|
1578
|
-
const suffix = quote === '"' ? "Quote" : "Apostrophe";
|
|
1579
|
-
const exit2 = state.enter("image");
|
|
1580
|
-
let subexit = state.enter("label");
|
|
1581
|
-
const tracker = state.createTracker(info);
|
|
1582
|
-
let value = tracker.move("![");
|
|
1583
|
-
value += tracker.move(
|
|
1584
|
-
state.safe(node2.alt, { before: value, after: "]", ...tracker.current() })
|
|
1585
|
-
);
|
|
1586
|
-
value += tracker.move("](");
|
|
1587
|
-
subexit();
|
|
1588
|
-
if (
|
|
1589
|
-
// If there’s no url but there is a title…
|
|
1590
|
-
!node2.url && node2.title || // If there are control characters or whitespace.
|
|
1591
|
-
/[\0- \u007F]/.test(node2.url)
|
|
1592
|
-
) {
|
|
1593
|
-
subexit = state.enter("destinationLiteral");
|
|
1594
|
-
value += tracker.move("<");
|
|
1595
|
-
value += tracker.move(
|
|
1596
|
-
state.safe(node2.url, { before: value, after: ">", ...tracker.current() })
|
|
1597
|
-
);
|
|
1598
|
-
value += tracker.move(">");
|
|
1599
|
-
} else {
|
|
1600
|
-
subexit = state.enter("destinationRaw");
|
|
1601
|
-
value += tracker.move(
|
|
1602
|
-
state.safe(node2.url, {
|
|
1603
|
-
before: value,
|
|
1604
|
-
after: node2.title ? " " : ")",
|
|
1605
|
-
...tracker.current()
|
|
1606
|
-
})
|
|
1607
|
-
);
|
|
1608
|
-
}
|
|
1609
|
-
subexit();
|
|
1610
|
-
if (node2.title) {
|
|
1611
|
-
subexit = state.enter(`title${suffix}`);
|
|
1612
|
-
value += tracker.move(" " + quote);
|
|
1613
|
-
value += tracker.move(
|
|
1614
|
-
state.safe(node2.title, {
|
|
1615
|
-
before: value,
|
|
1616
|
-
after: quote,
|
|
1617
|
-
...tracker.current()
|
|
1618
|
-
})
|
|
1619
|
-
);
|
|
1620
|
-
value += tracker.move(quote);
|
|
1621
|
-
subexit();
|
|
1622
|
-
}
|
|
1623
|
-
value += tracker.move(")");
|
|
1624
|
-
exit2();
|
|
1625
|
-
return value;
|
|
1626
|
-
}
|
|
1627
|
-
function imagePeek() {
|
|
1628
|
-
return "!";
|
|
1629
|
-
}
|
|
1630
|
-
imageReference.peek = imageReferencePeek;
|
|
1631
|
-
function imageReference(node2, _, state, info) {
|
|
1632
|
-
const type = node2.referenceType;
|
|
1633
|
-
const exit2 = state.enter("imageReference");
|
|
1634
|
-
let subexit = state.enter("label");
|
|
1635
|
-
const tracker = state.createTracker(info);
|
|
1636
|
-
let value = tracker.move("![");
|
|
1637
|
-
const alt = state.safe(node2.alt, {
|
|
1638
|
-
before: value,
|
|
1639
|
-
after: "]",
|
|
1640
|
-
...tracker.current()
|
|
1641
|
-
});
|
|
1642
|
-
value += tracker.move(alt + "][");
|
|
1643
|
-
subexit();
|
|
1644
|
-
const stack = state.stack;
|
|
1645
|
-
state.stack = [];
|
|
1646
|
-
subexit = state.enter("reference");
|
|
1647
|
-
const reference = state.safe(state.associationId(node2), {
|
|
1648
|
-
before: value,
|
|
1649
|
-
after: "]",
|
|
1650
|
-
...tracker.current()
|
|
1651
|
-
});
|
|
1652
|
-
subexit();
|
|
1653
|
-
state.stack = stack;
|
|
1654
|
-
exit2();
|
|
1655
|
-
if (type === "full" || !alt || alt !== reference) {
|
|
1656
|
-
value += tracker.move(reference + "]");
|
|
1657
|
-
} else if (type === "shortcut") {
|
|
1658
|
-
value = value.slice(0, -1);
|
|
1659
|
-
} else {
|
|
1660
|
-
value += tracker.move("]");
|
|
1661
|
-
}
|
|
1662
|
-
return value;
|
|
1663
|
-
}
|
|
1664
|
-
function imageReferencePeek() {
|
|
1665
|
-
return "!";
|
|
1666
|
-
}
|
|
1667
|
-
inlineCode.peek = inlineCodePeek;
|
|
1668
|
-
function inlineCode(node2, _, state) {
|
|
1669
|
-
let value = node2.value || "";
|
|
1670
|
-
let sequence = "`";
|
|
1671
|
-
let index = -1;
|
|
1672
|
-
while (new RegExp("(^|[^`])" + sequence + "([^`]|$)").test(value)) {
|
|
1673
|
-
sequence += "`";
|
|
1674
|
-
}
|
|
1675
|
-
if (/[^ \r\n]/.test(value) && (/^[ \r\n]/.test(value) && /[ \r\n]$/.test(value) || /^`|`$/.test(value))) {
|
|
1676
|
-
value = " " + value + " ";
|
|
1677
|
-
}
|
|
1678
|
-
while (++index < state.unsafe.length) {
|
|
1679
|
-
const pattern = state.unsafe[index];
|
|
1680
|
-
const expression = state.compilePattern(pattern);
|
|
1681
|
-
let match;
|
|
1682
|
-
if (!pattern.atBreak) continue;
|
|
1683
|
-
while (match = expression.exec(value)) {
|
|
1684
|
-
let position = match.index;
|
|
1685
|
-
if (value.charCodeAt(position) === 10 && value.charCodeAt(position - 1) === 13) {
|
|
1686
|
-
position--;
|
|
1687
|
-
}
|
|
1688
|
-
value = value.slice(0, position) + " " + value.slice(match.index + 1);
|
|
1689
|
-
}
|
|
1690
|
-
}
|
|
1691
|
-
return sequence + value + sequence;
|
|
1692
|
-
}
|
|
1693
|
-
function inlineCodePeek() {
|
|
1694
|
-
return "`";
|
|
1695
|
-
}
|
|
1696
|
-
function formatLinkAsAutolink(node2, state) {
|
|
1697
|
-
const raw = toString(node2);
|
|
1698
|
-
return Boolean(
|
|
1699
|
-
!state.options.resourceLink && // If there’s a url…
|
|
1700
|
-
node2.url && // And there’s a no title…
|
|
1701
|
-
!node2.title && // And the content of `node` is a single text node…
|
|
1702
|
-
node2.children && node2.children.length === 1 && node2.children[0].type === "text" && // And if the url is the same as the content…
|
|
1703
|
-
(raw === node2.url || "mailto:" + raw === node2.url) && // And that starts w/ a protocol…
|
|
1704
|
-
/^[a-z][a-z+.-]+:/i.test(node2.url) && // And that doesn’t contain ASCII control codes (character escapes and
|
|
1705
|
-
// references don’t work), space, or angle brackets…
|
|
1706
|
-
!/[\0- <>\u007F]/.test(node2.url)
|
|
1707
|
-
);
|
|
1708
|
-
}
|
|
1709
|
-
link.peek = linkPeek;
|
|
1710
|
-
function link(node2, _, state, info) {
|
|
1711
|
-
const quote = checkQuote(state);
|
|
1712
|
-
const suffix = quote === '"' ? "Quote" : "Apostrophe";
|
|
1713
|
-
const tracker = state.createTracker(info);
|
|
1714
|
-
let exit2;
|
|
1715
|
-
let subexit;
|
|
1716
|
-
if (formatLinkAsAutolink(node2, state)) {
|
|
1717
|
-
const stack = state.stack;
|
|
1718
|
-
state.stack = [];
|
|
1719
|
-
exit2 = state.enter("autolink");
|
|
1720
|
-
let value2 = tracker.move("<");
|
|
1721
|
-
value2 += tracker.move(
|
|
1722
|
-
state.containerPhrasing(node2, {
|
|
1723
|
-
before: value2,
|
|
1724
|
-
after: ">",
|
|
1725
|
-
...tracker.current()
|
|
1726
|
-
})
|
|
1727
|
-
);
|
|
1728
|
-
value2 += tracker.move(">");
|
|
1729
|
-
exit2();
|
|
1730
|
-
state.stack = stack;
|
|
1731
|
-
return value2;
|
|
1732
|
-
}
|
|
1733
|
-
exit2 = state.enter("link");
|
|
1734
|
-
subexit = state.enter("label");
|
|
1735
|
-
let value = tracker.move("[");
|
|
1736
|
-
value += tracker.move(
|
|
1737
|
-
state.containerPhrasing(node2, {
|
|
1738
|
-
before: value,
|
|
1739
|
-
after: "](",
|
|
1740
|
-
...tracker.current()
|
|
1741
|
-
})
|
|
1742
|
-
);
|
|
1743
|
-
value += tracker.move("](");
|
|
1744
|
-
subexit();
|
|
1745
|
-
if (
|
|
1746
|
-
// If there’s no url but there is a title…
|
|
1747
|
-
!node2.url && node2.title || // If there are control characters or whitespace.
|
|
1748
|
-
/[\0- \u007F]/.test(node2.url)
|
|
1749
|
-
) {
|
|
1750
|
-
subexit = state.enter("destinationLiteral");
|
|
1751
|
-
value += tracker.move("<");
|
|
1752
|
-
value += tracker.move(
|
|
1753
|
-
state.safe(node2.url, { before: value, after: ">", ...tracker.current() })
|
|
1754
|
-
);
|
|
1755
|
-
value += tracker.move(">");
|
|
1756
|
-
} else {
|
|
1757
|
-
subexit = state.enter("destinationRaw");
|
|
1758
|
-
value += tracker.move(
|
|
1759
|
-
state.safe(node2.url, {
|
|
1760
|
-
before: value,
|
|
1761
|
-
after: node2.title ? " " : ")",
|
|
1762
|
-
...tracker.current()
|
|
1763
|
-
})
|
|
1764
|
-
);
|
|
1765
|
-
}
|
|
1766
|
-
subexit();
|
|
1767
|
-
if (node2.title) {
|
|
1768
|
-
subexit = state.enter(`title${suffix}`);
|
|
1769
|
-
value += tracker.move(" " + quote);
|
|
1770
|
-
value += tracker.move(
|
|
1771
|
-
state.safe(node2.title, {
|
|
1772
|
-
before: value,
|
|
1773
|
-
after: quote,
|
|
1774
|
-
...tracker.current()
|
|
1775
|
-
})
|
|
1776
|
-
);
|
|
1777
|
-
value += tracker.move(quote);
|
|
1778
|
-
subexit();
|
|
1779
|
-
}
|
|
1780
|
-
value += tracker.move(")");
|
|
1781
|
-
exit2();
|
|
1782
|
-
return value;
|
|
1783
|
-
}
|
|
1784
|
-
function linkPeek(node2, _, state) {
|
|
1785
|
-
return formatLinkAsAutolink(node2, state) ? "<" : "[";
|
|
1786
|
-
}
|
|
1787
|
-
linkReference.peek = linkReferencePeek;
|
|
1788
|
-
function linkReference(node2, _, state, info) {
|
|
1789
|
-
const type = node2.referenceType;
|
|
1790
|
-
const exit2 = state.enter("linkReference");
|
|
1791
|
-
let subexit = state.enter("label");
|
|
1792
|
-
const tracker = state.createTracker(info);
|
|
1793
|
-
let value = tracker.move("[");
|
|
1794
|
-
const text2 = state.containerPhrasing(node2, {
|
|
1795
|
-
before: value,
|
|
1796
|
-
after: "]",
|
|
1797
|
-
...tracker.current()
|
|
1798
|
-
});
|
|
1799
|
-
value += tracker.move(text2 + "][");
|
|
1800
|
-
subexit();
|
|
1801
|
-
const stack = state.stack;
|
|
1802
|
-
state.stack = [];
|
|
1803
|
-
subexit = state.enter("reference");
|
|
1804
|
-
const reference = state.safe(state.associationId(node2), {
|
|
1805
|
-
before: value,
|
|
1806
|
-
after: "]",
|
|
1807
|
-
...tracker.current()
|
|
1808
|
-
});
|
|
1809
|
-
subexit();
|
|
1810
|
-
state.stack = stack;
|
|
1811
|
-
exit2();
|
|
1812
|
-
if (type === "full" || !text2 || text2 !== reference) {
|
|
1813
|
-
value += tracker.move(reference + "]");
|
|
1814
|
-
} else if (type === "shortcut") {
|
|
1815
|
-
value = value.slice(0, -1);
|
|
1816
|
-
} else {
|
|
1817
|
-
value += tracker.move("]");
|
|
1818
|
-
}
|
|
1819
|
-
return value;
|
|
1820
|
-
}
|
|
1821
|
-
function linkReferencePeek() {
|
|
1822
|
-
return "[";
|
|
1823
|
-
}
|
|
1824
|
-
function checkBullet(state) {
|
|
1825
|
-
const marker = state.options.bullet || "*";
|
|
1826
|
-
if (marker !== "*" && marker !== "+" && marker !== "-") {
|
|
1827
|
-
throw new Error(
|
|
1828
|
-
"Cannot serialize items with `" + marker + "` for `options.bullet`, expected `*`, `+`, or `-`"
|
|
1829
|
-
);
|
|
1830
|
-
}
|
|
1831
|
-
return marker;
|
|
1832
|
-
}
|
|
1833
|
-
function checkBulletOther(state) {
|
|
1834
|
-
const bullet = checkBullet(state);
|
|
1835
|
-
const bulletOther = state.options.bulletOther;
|
|
1836
|
-
if (!bulletOther) {
|
|
1837
|
-
return bullet === "*" ? "-" : "*";
|
|
1838
|
-
}
|
|
1839
|
-
if (bulletOther !== "*" && bulletOther !== "+" && bulletOther !== "-") {
|
|
1840
|
-
throw new Error(
|
|
1841
|
-
"Cannot serialize items with `" + bulletOther + "` for `options.bulletOther`, expected `*`, `+`, or `-`"
|
|
1842
|
-
);
|
|
1843
|
-
}
|
|
1844
|
-
if (bulletOther === bullet) {
|
|
1845
|
-
throw new Error(
|
|
1846
|
-
"Expected `bullet` (`" + bullet + "`) and `bulletOther` (`" + bulletOther + "`) to be different"
|
|
1847
|
-
);
|
|
1848
|
-
}
|
|
1849
|
-
return bulletOther;
|
|
1850
|
-
}
|
|
1851
|
-
function checkBulletOrdered(state) {
|
|
1852
|
-
const marker = state.options.bulletOrdered || ".";
|
|
1853
|
-
if (marker !== "." && marker !== ")") {
|
|
1854
|
-
throw new Error(
|
|
1855
|
-
"Cannot serialize items with `" + marker + "` for `options.bulletOrdered`, expected `.` or `)`"
|
|
1856
|
-
);
|
|
1857
|
-
}
|
|
1858
|
-
return marker;
|
|
1859
|
-
}
|
|
1860
|
-
function checkRule(state) {
|
|
1861
|
-
const marker = state.options.rule || "*";
|
|
1862
|
-
if (marker !== "*" && marker !== "-" && marker !== "_") {
|
|
1863
|
-
throw new Error(
|
|
1864
|
-
"Cannot serialize rules with `" + marker + "` for `options.rule`, expected `*`, `-`, or `_`"
|
|
1865
|
-
);
|
|
1866
|
-
}
|
|
1867
|
-
return marker;
|
|
1868
|
-
}
|
|
1869
|
-
function list(node2, parent, state, info) {
|
|
1870
|
-
const exit2 = state.enter("list");
|
|
1871
|
-
const bulletCurrent = state.bulletCurrent;
|
|
1872
|
-
let bullet = node2.ordered ? checkBulletOrdered(state) : checkBullet(state);
|
|
1873
|
-
const bulletOther = node2.ordered ? bullet === "." ? ")" : "." : checkBulletOther(state);
|
|
1874
|
-
let useDifferentMarker = parent && state.bulletLastUsed ? bullet === state.bulletLastUsed : false;
|
|
1875
|
-
if (!node2.ordered) {
|
|
1876
|
-
const firstListItem = node2.children ? node2.children[0] : void 0;
|
|
1877
|
-
if (
|
|
1878
|
-
// Bullet could be used as a thematic break marker:
|
|
1879
|
-
(bullet === "*" || bullet === "-") && // Empty first list item:
|
|
1880
|
-
firstListItem && (!firstListItem.children || !firstListItem.children[0]) && // Directly in two other list items:
|
|
1881
|
-
state.stack[state.stack.length - 1] === "list" && state.stack[state.stack.length - 2] === "listItem" && state.stack[state.stack.length - 3] === "list" && state.stack[state.stack.length - 4] === "listItem" && // That are each the first child.
|
|
1882
|
-
state.indexStack[state.indexStack.length - 1] === 0 && state.indexStack[state.indexStack.length - 2] === 0 && state.indexStack[state.indexStack.length - 3] === 0
|
|
1883
|
-
) {
|
|
1884
|
-
useDifferentMarker = true;
|
|
1885
|
-
}
|
|
1886
|
-
if (checkRule(state) === bullet && firstListItem) {
|
|
1887
|
-
let index = -1;
|
|
1888
|
-
while (++index < node2.children.length) {
|
|
1889
|
-
const item = node2.children[index];
|
|
1890
|
-
if (item && item.type === "listItem" && item.children && item.children[0] && item.children[0].type === "thematicBreak") {
|
|
1891
|
-
useDifferentMarker = true;
|
|
1892
|
-
break;
|
|
1893
|
-
}
|
|
1894
|
-
}
|
|
1895
|
-
}
|
|
1896
|
-
}
|
|
1897
|
-
if (useDifferentMarker) {
|
|
1898
|
-
bullet = bulletOther;
|
|
1899
|
-
}
|
|
1900
|
-
state.bulletCurrent = bullet;
|
|
1901
|
-
const value = state.containerFlow(node2, info);
|
|
1902
|
-
state.bulletLastUsed = bullet;
|
|
1903
|
-
state.bulletCurrent = bulletCurrent;
|
|
1904
|
-
exit2();
|
|
1905
|
-
return value;
|
|
1906
|
-
}
|
|
1907
|
-
function checkListItemIndent(state) {
|
|
1908
|
-
const style = state.options.listItemIndent || "one";
|
|
1909
|
-
if (style !== "tab" && style !== "one" && style !== "mixed") {
|
|
1910
|
-
throw new Error(
|
|
1911
|
-
"Cannot serialize items with `" + style + "` for `options.listItemIndent`, expected `tab`, `one`, or `mixed`"
|
|
1912
|
-
);
|
|
1913
|
-
}
|
|
1914
|
-
return style;
|
|
1915
|
-
}
|
|
1916
|
-
function listItem(node2, parent, state, info) {
|
|
1917
|
-
const listItemIndent = checkListItemIndent(state);
|
|
1918
|
-
let bullet = state.bulletCurrent || checkBullet(state);
|
|
1919
|
-
if (parent && parent.type === "list" && parent.ordered) {
|
|
1920
|
-
bullet = (typeof parent.start === "number" && parent.start > -1 ? parent.start : 1) + (state.options.incrementListMarker === false ? 0 : parent.children.indexOf(node2)) + bullet;
|
|
1921
|
-
}
|
|
1922
|
-
let size = bullet.length + 1;
|
|
1923
|
-
if (listItemIndent === "tab" || listItemIndent === "mixed" && (parent && parent.type === "list" && parent.spread || node2.spread)) {
|
|
1924
|
-
size = Math.ceil(size / 4) * 4;
|
|
1925
|
-
}
|
|
1926
|
-
const tracker = state.createTracker(info);
|
|
1927
|
-
tracker.move(bullet + " ".repeat(size - bullet.length));
|
|
1928
|
-
tracker.shift(size);
|
|
1929
|
-
const exit2 = state.enter("listItem");
|
|
1930
|
-
const value = state.indentLines(
|
|
1931
|
-
state.containerFlow(node2, tracker.current()),
|
|
1932
|
-
map2
|
|
1933
|
-
);
|
|
1934
|
-
exit2();
|
|
1935
|
-
return value;
|
|
1936
|
-
function map2(line, index, blank) {
|
|
1937
|
-
if (index) {
|
|
1938
|
-
return (blank ? "" : " ".repeat(size)) + line;
|
|
1939
|
-
}
|
|
1940
|
-
return (blank ? bullet : bullet + " ".repeat(size - bullet.length)) + line;
|
|
1941
|
-
}
|
|
1942
|
-
}
|
|
1943
|
-
function paragraph(node2, _, state, info) {
|
|
1944
|
-
const exit2 = state.enter("paragraph");
|
|
1945
|
-
const subexit = state.enter("phrasing");
|
|
1946
|
-
const value = state.containerPhrasing(node2, info);
|
|
1947
|
-
subexit();
|
|
1948
|
-
exit2();
|
|
1949
|
-
return value;
|
|
1950
|
-
}
|
|
1951
|
-
const phrasing = (
|
|
1952
|
-
/** @type {(node?: unknown) => node is Exclude<PhrasingContent, Html>} */
|
|
1953
|
-
convert([
|
|
1954
|
-
"break",
|
|
1955
|
-
"delete",
|
|
1956
|
-
"emphasis",
|
|
1957
|
-
// To do: next major: removed since footnotes were added to GFM.
|
|
1958
|
-
"footnote",
|
|
1959
|
-
"footnoteReference",
|
|
1960
|
-
"image",
|
|
1961
|
-
"imageReference",
|
|
1962
|
-
"inlineCode",
|
|
1963
|
-
// Enabled by `mdast-util-math`:
|
|
1964
|
-
"inlineMath",
|
|
1965
|
-
"link",
|
|
1966
|
-
"linkReference",
|
|
1967
|
-
// Enabled by `mdast-util-mdx`:
|
|
1968
|
-
"mdxJsxTextElement",
|
|
1969
|
-
// Enabled by `mdast-util-mdx`:
|
|
1970
|
-
"mdxTextExpression",
|
|
1971
|
-
"strong",
|
|
1972
|
-
"text",
|
|
1973
|
-
// Enabled by `mdast-util-directive`:
|
|
1974
|
-
"textDirective"
|
|
1975
|
-
])
|
|
1976
|
-
);
|
|
1977
|
-
function root(node2, _, state, info) {
|
|
1978
|
-
const hasPhrasing = node2.children.some(function(d) {
|
|
1979
|
-
return phrasing(d);
|
|
1980
|
-
});
|
|
1981
|
-
const container = hasPhrasing ? state.containerPhrasing : state.containerFlow;
|
|
1982
|
-
return container.call(state, node2, info);
|
|
1983
|
-
}
|
|
1984
|
-
function checkStrong(state) {
|
|
1985
|
-
const marker = state.options.strong || "*";
|
|
1986
|
-
if (marker !== "*" && marker !== "_") {
|
|
1987
|
-
throw new Error(
|
|
1988
|
-
"Cannot serialize strong with `" + marker + "` for `options.strong`, expected `*`, or `_`"
|
|
1989
|
-
);
|
|
1990
|
-
}
|
|
1991
|
-
return marker;
|
|
1992
|
-
}
|
|
1993
|
-
strong.peek = strongPeek;
|
|
1994
|
-
function strong(node2, _, state, info) {
|
|
1995
|
-
const marker = checkStrong(state);
|
|
1996
|
-
const exit2 = state.enter("strong");
|
|
1997
|
-
const tracker = state.createTracker(info);
|
|
1998
|
-
const before = tracker.move(marker + marker);
|
|
1999
|
-
let between = tracker.move(
|
|
2000
|
-
state.containerPhrasing(node2, {
|
|
2001
|
-
after: marker,
|
|
2002
|
-
before,
|
|
2003
|
-
...tracker.current()
|
|
2004
|
-
})
|
|
2005
|
-
);
|
|
2006
|
-
const betweenHead = between.charCodeAt(0);
|
|
2007
|
-
const open = encodeInfo(
|
|
2008
|
-
info.before.charCodeAt(info.before.length - 1),
|
|
2009
|
-
betweenHead,
|
|
2010
|
-
marker
|
|
2011
|
-
);
|
|
2012
|
-
if (open.inside) {
|
|
2013
|
-
between = encodeCharacterReference(betweenHead) + between.slice(1);
|
|
2014
|
-
}
|
|
2015
|
-
const betweenTail = between.charCodeAt(between.length - 1);
|
|
2016
|
-
const close = encodeInfo(info.after.charCodeAt(0), betweenTail, marker);
|
|
2017
|
-
if (close.inside) {
|
|
2018
|
-
between = between.slice(0, -1) + encodeCharacterReference(betweenTail);
|
|
2019
|
-
}
|
|
2020
|
-
const after = tracker.move(marker + marker);
|
|
2021
|
-
exit2();
|
|
2022
|
-
state.attentionEncodeSurroundingInfo = {
|
|
2023
|
-
after: close.outside,
|
|
2024
|
-
before: open.outside
|
|
2025
|
-
};
|
|
2026
|
-
return before + between + after;
|
|
2027
|
-
}
|
|
2028
|
-
function strongPeek(_, _1, state) {
|
|
2029
|
-
return state.options.strong || "*";
|
|
2030
|
-
}
|
|
2031
|
-
function text$1(node2, _, state, info) {
|
|
2032
|
-
return state.safe(node2.value, info);
|
|
2033
|
-
}
|
|
2034
|
-
function checkRuleRepetition(state) {
|
|
2035
|
-
const repetition = state.options.ruleRepetition || 3;
|
|
2036
|
-
if (repetition < 3) {
|
|
2037
|
-
throw new Error(
|
|
2038
|
-
"Cannot serialize rules with repetition `" + repetition + "` for `options.ruleRepetition`, expected `3` or more"
|
|
2039
|
-
);
|
|
2040
|
-
}
|
|
2041
|
-
return repetition;
|
|
2042
|
-
}
|
|
2043
|
-
function thematicBreak(_, _1, state) {
|
|
2044
|
-
const value = (checkRule(state) + (state.options.ruleSpaces ? " " : "")).repeat(checkRuleRepetition(state));
|
|
2045
|
-
return state.options.ruleSpaces ? value.slice(0, -1) : value;
|
|
2046
|
-
}
|
|
2047
|
-
const handle = {
|
|
2048
|
-
blockquote,
|
|
2049
|
-
break: hardBreak,
|
|
2050
|
-
code: code$1,
|
|
2051
|
-
definition,
|
|
2052
|
-
emphasis,
|
|
2053
|
-
hardBreak,
|
|
2054
|
-
heading,
|
|
2055
|
-
html,
|
|
2056
|
-
image,
|
|
2057
|
-
imageReference,
|
|
2058
|
-
inlineCode,
|
|
2059
|
-
link,
|
|
2060
|
-
linkReference,
|
|
2061
|
-
list,
|
|
2062
|
-
listItem,
|
|
2063
|
-
paragraph,
|
|
2064
|
-
root,
|
|
2065
|
-
strong,
|
|
2066
|
-
text: text$1,
|
|
2067
|
-
thematicBreak
|
|
2068
|
-
};
|
|
2069
|
-
function gfmTableFromMarkdown() {
|
|
2070
|
-
return {
|
|
2071
|
-
enter: {
|
|
2072
|
-
table: enterTable,
|
|
2073
|
-
tableData: enterCell,
|
|
2074
|
-
tableHeader: enterCell,
|
|
2075
|
-
tableRow: enterRow
|
|
2076
|
-
},
|
|
2077
|
-
exit: {
|
|
2078
|
-
codeText: exitCodeText,
|
|
2079
|
-
table: exitTable,
|
|
2080
|
-
tableData: exit,
|
|
2081
|
-
tableHeader: exit,
|
|
2082
|
-
tableRow: exit
|
|
2083
|
-
}
|
|
2084
|
-
};
|
|
2085
|
-
}
|
|
2086
|
-
function enterTable(token) {
|
|
2087
|
-
const align = token._align;
|
|
2088
|
-
this.enter(
|
|
2089
|
-
{
|
|
2090
|
-
type: "table",
|
|
2091
|
-
align: align.map(function(d) {
|
|
2092
|
-
return d === "none" ? null : d;
|
|
2093
|
-
}),
|
|
2094
|
-
children: []
|
|
2095
|
-
},
|
|
2096
|
-
token
|
|
2097
|
-
);
|
|
2098
|
-
this.data.inTable = true;
|
|
2099
|
-
}
|
|
2100
|
-
function exitTable(token) {
|
|
2101
|
-
this.exit(token);
|
|
2102
|
-
this.data.inTable = void 0;
|
|
2103
|
-
}
|
|
2104
|
-
function enterRow(token) {
|
|
2105
|
-
this.enter({ type: "tableRow", children: [] }, token);
|
|
2106
|
-
}
|
|
2107
|
-
function exit(token) {
|
|
2108
|
-
this.exit(token);
|
|
2109
|
-
}
|
|
2110
|
-
function enterCell(token) {
|
|
2111
|
-
this.enter({ type: "tableCell", children: [] }, token);
|
|
2112
|
-
}
|
|
2113
|
-
function exitCodeText(token) {
|
|
2114
|
-
let value = this.resume();
|
|
2115
|
-
if (this.data.inTable) {
|
|
2116
|
-
value = value.replace(/\\([\\|])/g, replace);
|
|
2117
|
-
}
|
|
2118
|
-
const node2 = this.stack[this.stack.length - 1];
|
|
2119
|
-
ok$1(node2.type === "inlineCode");
|
|
2120
|
-
node2.value = value;
|
|
2121
|
-
this.exit(token);
|
|
2122
|
-
}
|
|
2123
|
-
function replace($0, $1) {
|
|
2124
|
-
return $1 === "|" ? $1 : $0;
|
|
2125
|
-
}
|
|
2126
|
-
function gfmTableToMarkdown(options) {
|
|
2127
|
-
const settings = options || {};
|
|
2128
|
-
const padding = settings.tableCellPadding;
|
|
2129
|
-
const alignDelimiters = settings.tablePipeAlign;
|
|
2130
|
-
const stringLength = settings.stringLength;
|
|
2131
|
-
const around = padding ? " " : "|";
|
|
2132
|
-
return {
|
|
2133
|
-
unsafe: [
|
|
2134
|
-
{ character: "\r", inConstruct: "tableCell" },
|
|
2135
|
-
{ character: "\n", inConstruct: "tableCell" },
|
|
2136
|
-
// A pipe, when followed by a tab or space (padding), or a dash or colon
|
|
2137
|
-
// (unpadded delimiter row), could result in a table.
|
|
2138
|
-
{ atBreak: true, character: "|", after: "[ :-]" },
|
|
2139
|
-
// A pipe in a cell must be encoded.
|
|
2140
|
-
{ character: "|", inConstruct: "tableCell" },
|
|
2141
|
-
// A colon must be followed by a dash, in which case it could start a
|
|
2142
|
-
// delimiter row.
|
|
2143
|
-
{ atBreak: true, character: ":", after: "-" },
|
|
2144
|
-
// A delimiter row can also start with a dash, when followed by more
|
|
2145
|
-
// dashes, a colon, or a pipe.
|
|
2146
|
-
// This is a stricter version than the built in check for lists, thematic
|
|
2147
|
-
// breaks, and setex heading underlines though:
|
|
2148
|
-
// <https://github.com/syntax-tree/mdast-util-to-markdown/blob/51a2038/lib/unsafe.js#L57>
|
|
2149
|
-
{ atBreak: true, character: "-", after: "[:|-]" }
|
|
2150
|
-
],
|
|
2151
|
-
handlers: {
|
|
2152
|
-
inlineCode: inlineCodeWithTable,
|
|
2153
|
-
table: handleTable,
|
|
2154
|
-
tableCell: handleTableCell,
|
|
2155
|
-
tableRow: handleTableRow
|
|
2156
|
-
}
|
|
2157
|
-
};
|
|
2158
|
-
function handleTable(node2, _, state, info) {
|
|
2159
|
-
return serializeData(handleTableAsData(node2, state, info), node2.align);
|
|
2160
|
-
}
|
|
2161
|
-
function handleTableRow(node2, _, state, info) {
|
|
2162
|
-
const row = handleTableRowAsData(node2, state, info);
|
|
2163
|
-
const value = serializeData([row]);
|
|
2164
|
-
return value.slice(0, value.indexOf("\n"));
|
|
2165
|
-
}
|
|
2166
|
-
function handleTableCell(node2, _, state, info) {
|
|
2167
|
-
const exit2 = state.enter("tableCell");
|
|
2168
|
-
const subexit = state.enter("phrasing");
|
|
2169
|
-
const value = state.containerPhrasing(node2, {
|
|
2170
|
-
...info,
|
|
2171
|
-
before: around,
|
|
2172
|
-
after: around
|
|
2173
|
-
});
|
|
2174
|
-
subexit();
|
|
2175
|
-
exit2();
|
|
2176
|
-
return value;
|
|
2177
|
-
}
|
|
2178
|
-
function serializeData(matrix, align) {
|
|
2179
|
-
return markdownTable(matrix, {
|
|
2180
|
-
align,
|
|
2181
|
-
// @ts-expect-error: `markdown-table` types should support `null`.
|
|
2182
|
-
alignDelimiters,
|
|
2183
|
-
// @ts-expect-error: `markdown-table` types should support `null`.
|
|
2184
|
-
padding,
|
|
2185
|
-
// @ts-expect-error: `markdown-table` types should support `null`.
|
|
2186
|
-
stringLength
|
|
2187
|
-
});
|
|
2188
|
-
}
|
|
2189
|
-
function handleTableAsData(node2, state, info) {
|
|
2190
|
-
const children = node2.children;
|
|
2191
|
-
let index = -1;
|
|
2192
|
-
const result = [];
|
|
2193
|
-
const subexit = state.enter("table");
|
|
2194
|
-
while (++index < children.length) {
|
|
2195
|
-
result[index] = handleTableRowAsData(children[index], state, info);
|
|
2196
|
-
}
|
|
2197
|
-
subexit();
|
|
2198
|
-
return result;
|
|
2199
|
-
}
|
|
2200
|
-
function handleTableRowAsData(node2, state, info) {
|
|
2201
|
-
const children = node2.children;
|
|
2202
|
-
let index = -1;
|
|
2203
|
-
const result = [];
|
|
2204
|
-
const subexit = state.enter("tableRow");
|
|
2205
|
-
while (++index < children.length) {
|
|
2206
|
-
result[index] = handleTableCell(children[index], node2, state, info);
|
|
2207
|
-
}
|
|
2208
|
-
subexit();
|
|
2209
|
-
return result;
|
|
2210
|
-
}
|
|
2211
|
-
function inlineCodeWithTable(node2, parent, state) {
|
|
2212
|
-
let value = handle.inlineCode(node2, parent, state);
|
|
2213
|
-
if (state.stack.includes("tableCell")) {
|
|
2214
|
-
value = value.replace(/\|/g, "\\$&");
|
|
2215
|
-
}
|
|
2216
|
-
return value;
|
|
2217
|
-
}
|
|
2218
|
-
}
|
|
2219
|
-
function gfmTaskListItemFromMarkdown() {
|
|
2220
|
-
return {
|
|
2221
|
-
exit: {
|
|
2222
|
-
taskListCheckValueChecked: exitCheck,
|
|
2223
|
-
taskListCheckValueUnchecked: exitCheck,
|
|
2224
|
-
paragraph: exitParagraphWithTaskListItem
|
|
2225
|
-
}
|
|
2226
|
-
};
|
|
2227
|
-
}
|
|
2228
|
-
function gfmTaskListItemToMarkdown() {
|
|
2229
|
-
return {
|
|
2230
|
-
unsafe: [{ atBreak: true, character: "-", after: "[:|-]" }],
|
|
2231
|
-
handlers: { listItem: listItemWithTaskListItem }
|
|
2232
|
-
};
|
|
2233
|
-
}
|
|
2234
|
-
function exitCheck(token) {
|
|
2235
|
-
const node2 = this.stack[this.stack.length - 2];
|
|
2236
|
-
ok$1(node2.type === "listItem");
|
|
2237
|
-
node2.checked = token.type === "taskListCheckValueChecked";
|
|
2238
|
-
}
|
|
2239
|
-
function exitParagraphWithTaskListItem(token) {
|
|
2240
|
-
const parent = this.stack[this.stack.length - 2];
|
|
2241
|
-
if (parent && parent.type === "listItem" && typeof parent.checked === "boolean") {
|
|
2242
|
-
const node2 = this.stack[this.stack.length - 1];
|
|
2243
|
-
ok$1(node2.type === "paragraph");
|
|
2244
|
-
const head = node2.children[0];
|
|
2245
|
-
if (head && head.type === "text") {
|
|
2246
|
-
const siblings = parent.children;
|
|
2247
|
-
let index = -1;
|
|
2248
|
-
let firstParaghraph;
|
|
2249
|
-
while (++index < siblings.length) {
|
|
2250
|
-
const sibling = siblings[index];
|
|
2251
|
-
if (sibling.type === "paragraph") {
|
|
2252
|
-
firstParaghraph = sibling;
|
|
2253
|
-
break;
|
|
2254
|
-
}
|
|
2255
|
-
}
|
|
2256
|
-
if (firstParaghraph === node2) {
|
|
2257
|
-
head.value = head.value.slice(1);
|
|
2258
|
-
if (head.value.length === 0) {
|
|
2259
|
-
node2.children.shift();
|
|
2260
|
-
} else if (node2.position && head.position && typeof head.position.start.offset === "number") {
|
|
2261
|
-
head.position.start.column++;
|
|
2262
|
-
head.position.start.offset++;
|
|
2263
|
-
node2.position.start = Object.assign({}, head.position.start);
|
|
2264
|
-
}
|
|
2265
|
-
}
|
|
2266
|
-
}
|
|
2267
|
-
}
|
|
2268
|
-
this.exit(token);
|
|
2269
|
-
}
|
|
2270
|
-
function listItemWithTaskListItem(node2, parent, state, info) {
|
|
2271
|
-
const head = node2.children[0];
|
|
2272
|
-
const checkable = typeof node2.checked === "boolean" && head && head.type === "paragraph";
|
|
2273
|
-
const checkbox = "[" + (node2.checked ? "x" : " ") + "] ";
|
|
2274
|
-
const tracker = state.createTracker(info);
|
|
2275
|
-
if (checkable) {
|
|
2276
|
-
tracker.move(checkbox);
|
|
2277
|
-
}
|
|
2278
|
-
let value = handle.listItem(node2, parent, state, {
|
|
2279
|
-
...info,
|
|
2280
|
-
...tracker.current()
|
|
2281
|
-
});
|
|
2282
|
-
if (checkable) {
|
|
2283
|
-
value = value.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/, check);
|
|
2284
|
-
}
|
|
2285
|
-
return value;
|
|
2286
|
-
function check($0) {
|
|
2287
|
-
return $0 + checkbox;
|
|
2288
|
-
}
|
|
2289
|
-
}
|
|
2290
|
-
function gfmFromMarkdown() {
|
|
2291
|
-
return [
|
|
2292
|
-
gfmAutolinkLiteralFromMarkdown(),
|
|
2293
|
-
gfmFootnoteFromMarkdown(),
|
|
2294
|
-
gfmStrikethroughFromMarkdown(),
|
|
2295
|
-
gfmTableFromMarkdown(),
|
|
2296
|
-
gfmTaskListItemFromMarkdown()
|
|
2297
|
-
];
|
|
2298
|
-
}
|
|
2299
|
-
function gfmToMarkdown(options) {
|
|
2300
|
-
return {
|
|
2301
|
-
extensions: [
|
|
2302
|
-
gfmAutolinkLiteralToMarkdown(),
|
|
2303
|
-
gfmFootnoteToMarkdown(options),
|
|
2304
|
-
gfmStrikethroughToMarkdown(),
|
|
2305
|
-
gfmTableToMarkdown(options),
|
|
2306
|
-
gfmTaskListItemToMarkdown()
|
|
2307
|
-
]
|
|
2308
|
-
};
|
|
2309
|
-
}
|
|
2310
|
-
function splice(list2, start, remove, items) {
|
|
2311
|
-
const end = list2.length;
|
|
2312
|
-
let chunkStart = 0;
|
|
2313
|
-
let parameters;
|
|
2314
|
-
if (start < 0) {
|
|
2315
|
-
start = -start > end ? 0 : end + start;
|
|
2316
|
-
} else {
|
|
2317
|
-
start = start > end ? end : start;
|
|
2318
|
-
}
|
|
2319
|
-
remove = remove > 0 ? remove : 0;
|
|
2320
|
-
if (items.length < 1e4) {
|
|
2321
|
-
parameters = Array.from(items);
|
|
2322
|
-
parameters.unshift(start, remove);
|
|
2323
|
-
list2.splice(...parameters);
|
|
2324
|
-
} else {
|
|
2325
|
-
if (remove) list2.splice(start, remove);
|
|
2326
|
-
while (chunkStart < items.length) {
|
|
2327
|
-
parameters = items.slice(chunkStart, chunkStart + 1e4);
|
|
2328
|
-
parameters.unshift(start, 0);
|
|
2329
|
-
list2.splice(...parameters);
|
|
2330
|
-
chunkStart += 1e4;
|
|
2331
|
-
start += 1e4;
|
|
2332
|
-
}
|
|
2333
|
-
}
|
|
2334
|
-
}
|
|
2335
|
-
const hasOwnProperty = {}.hasOwnProperty;
|
|
2336
|
-
function combineExtensions(extensions) {
|
|
2337
|
-
const all2 = {};
|
|
2338
|
-
let index = -1;
|
|
2339
|
-
while (++index < extensions.length) {
|
|
2340
|
-
syntaxExtension(all2, extensions[index]);
|
|
2341
|
-
}
|
|
2342
|
-
return all2;
|
|
2343
|
-
}
|
|
2344
|
-
function syntaxExtension(all2, extension) {
|
|
2345
|
-
let hook;
|
|
2346
|
-
for (hook in extension) {
|
|
2347
|
-
const maybe = hasOwnProperty.call(all2, hook) ? all2[hook] : void 0;
|
|
2348
|
-
const left = maybe || (all2[hook] = {});
|
|
2349
|
-
const right = extension[hook];
|
|
2350
|
-
let code2;
|
|
2351
|
-
if (right) {
|
|
2352
|
-
for (code2 in right) {
|
|
2353
|
-
if (!hasOwnProperty.call(left, code2)) left[code2] = [];
|
|
2354
|
-
const value = right[code2];
|
|
2355
|
-
constructs(
|
|
2356
|
-
// @ts-expect-error Looks like a list.
|
|
2357
|
-
left[code2],
|
|
2358
|
-
Array.isArray(value) ? value : value ? [value] : []
|
|
2359
|
-
);
|
|
2360
|
-
}
|
|
2361
|
-
}
|
|
2362
|
-
}
|
|
2363
|
-
}
|
|
2364
|
-
function constructs(existing, list2) {
|
|
2365
|
-
let index = -1;
|
|
2366
|
-
const before = [];
|
|
2367
|
-
while (++index < list2.length) {
|
|
2368
|
-
(list2[index].add === "after" ? existing : before).push(list2[index]);
|
|
2369
|
-
}
|
|
2370
|
-
splice(existing, 0, 0, before);
|
|
2371
|
-
}
|
|
2372
|
-
const wwwPrefix = {
|
|
2373
|
-
tokenize: tokenizeWwwPrefix,
|
|
2374
|
-
partial: true
|
|
2375
|
-
};
|
|
2376
|
-
const domain = {
|
|
2377
|
-
tokenize: tokenizeDomain,
|
|
2378
|
-
partial: true
|
|
2379
|
-
};
|
|
2380
|
-
const path = {
|
|
2381
|
-
tokenize: tokenizePath,
|
|
2382
|
-
partial: true
|
|
2383
|
-
};
|
|
2384
|
-
const trail = {
|
|
2385
|
-
tokenize: tokenizeTrail,
|
|
2386
|
-
partial: true
|
|
2387
|
-
};
|
|
2388
|
-
const emailDomainDotTrail = {
|
|
2389
|
-
tokenize: tokenizeEmailDomainDotTrail,
|
|
2390
|
-
partial: true
|
|
2391
|
-
};
|
|
2392
|
-
const wwwAutolink = {
|
|
2393
|
-
name: "wwwAutolink",
|
|
2394
|
-
tokenize: tokenizeWwwAutolink,
|
|
2395
|
-
previous: previousWww
|
|
2396
|
-
};
|
|
2397
|
-
const protocolAutolink = {
|
|
2398
|
-
name: "protocolAutolink",
|
|
2399
|
-
tokenize: tokenizeProtocolAutolink,
|
|
2400
|
-
previous: previousProtocol
|
|
2401
|
-
};
|
|
2402
|
-
const emailAutolink = {
|
|
2403
|
-
name: "emailAutolink",
|
|
2404
|
-
tokenize: tokenizeEmailAutolink,
|
|
2405
|
-
previous: previousEmail
|
|
2406
|
-
};
|
|
2407
|
-
const text = {};
|
|
2408
|
-
function gfmAutolinkLiteral() {
|
|
2409
|
-
return {
|
|
2410
|
-
text
|
|
2411
|
-
};
|
|
2412
|
-
}
|
|
2413
|
-
let code = 48;
|
|
2414
|
-
while (code < 123) {
|
|
2415
|
-
text[code] = emailAutolink;
|
|
2416
|
-
code++;
|
|
2417
|
-
if (code === 58) code = 65;
|
|
2418
|
-
else if (code === 91) code = 97;
|
|
2419
|
-
}
|
|
2420
|
-
text[43] = emailAutolink;
|
|
2421
|
-
text[45] = emailAutolink;
|
|
2422
|
-
text[46] = emailAutolink;
|
|
2423
|
-
text[95] = emailAutolink;
|
|
2424
|
-
text[72] = [emailAutolink, protocolAutolink];
|
|
2425
|
-
text[104] = [emailAutolink, protocolAutolink];
|
|
2426
|
-
text[87] = [emailAutolink, wwwAutolink];
|
|
2427
|
-
text[119] = [emailAutolink, wwwAutolink];
|
|
2428
|
-
function tokenizeEmailAutolink(effects, ok2, nok) {
|
|
2429
|
-
const self = this;
|
|
2430
|
-
let dot;
|
|
2431
|
-
let data;
|
|
2432
|
-
return start;
|
|
2433
|
-
function start(code2) {
|
|
2434
|
-
if (!gfmAtext(code2) || !previousEmail.call(self, self.previous) || previousUnbalanced(self.events)) {
|
|
2435
|
-
return nok(code2);
|
|
2436
|
-
}
|
|
2437
|
-
effects.enter("literalAutolink");
|
|
2438
|
-
effects.enter("literalAutolinkEmail");
|
|
2439
|
-
return atext(code2);
|
|
2440
|
-
}
|
|
2441
|
-
function atext(code2) {
|
|
2442
|
-
if (gfmAtext(code2)) {
|
|
2443
|
-
effects.consume(code2);
|
|
2444
|
-
return atext;
|
|
2445
|
-
}
|
|
2446
|
-
if (code2 === 64) {
|
|
2447
|
-
effects.consume(code2);
|
|
2448
|
-
return emailDomain;
|
|
2449
|
-
}
|
|
2450
|
-
return nok(code2);
|
|
2451
|
-
}
|
|
2452
|
-
function emailDomain(code2) {
|
|
2453
|
-
if (code2 === 46) {
|
|
2454
|
-
return effects.check(emailDomainDotTrail, emailDomainAfter, emailDomainDot)(code2);
|
|
2455
|
-
}
|
|
2456
|
-
if (code2 === 45 || code2 === 95 || asciiAlphanumeric(code2)) {
|
|
2457
|
-
data = true;
|
|
2458
|
-
effects.consume(code2);
|
|
2459
|
-
return emailDomain;
|
|
2460
|
-
}
|
|
2461
|
-
return emailDomainAfter(code2);
|
|
2462
|
-
}
|
|
2463
|
-
function emailDomainDot(code2) {
|
|
2464
|
-
effects.consume(code2);
|
|
2465
|
-
dot = true;
|
|
2466
|
-
return emailDomain;
|
|
2467
|
-
}
|
|
2468
|
-
function emailDomainAfter(code2) {
|
|
2469
|
-
if (data && dot && asciiAlpha(self.previous)) {
|
|
2470
|
-
effects.exit("literalAutolinkEmail");
|
|
2471
|
-
effects.exit("literalAutolink");
|
|
2472
|
-
return ok2(code2);
|
|
2473
|
-
}
|
|
2474
|
-
return nok(code2);
|
|
2475
|
-
}
|
|
2476
|
-
}
|
|
2477
|
-
function tokenizeWwwAutolink(effects, ok2, nok) {
|
|
2478
|
-
const self = this;
|
|
2479
|
-
return wwwStart;
|
|
2480
|
-
function wwwStart(code2) {
|
|
2481
|
-
if (code2 !== 87 && code2 !== 119 || !previousWww.call(self, self.previous) || previousUnbalanced(self.events)) {
|
|
2482
|
-
return nok(code2);
|
|
2483
|
-
}
|
|
2484
|
-
effects.enter("literalAutolink");
|
|
2485
|
-
effects.enter("literalAutolinkWww");
|
|
2486
|
-
return effects.check(wwwPrefix, effects.attempt(domain, effects.attempt(path, wwwAfter), nok), nok)(code2);
|
|
2487
|
-
}
|
|
2488
|
-
function wwwAfter(code2) {
|
|
2489
|
-
effects.exit("literalAutolinkWww");
|
|
2490
|
-
effects.exit("literalAutolink");
|
|
2491
|
-
return ok2(code2);
|
|
2492
|
-
}
|
|
2493
|
-
}
|
|
2494
|
-
function tokenizeProtocolAutolink(effects, ok2, nok) {
|
|
2495
|
-
const self = this;
|
|
2496
|
-
let buffer = "";
|
|
2497
|
-
let seen = false;
|
|
2498
|
-
return protocolStart;
|
|
2499
|
-
function protocolStart(code2) {
|
|
2500
|
-
if ((code2 === 72 || code2 === 104) && previousProtocol.call(self, self.previous) && !previousUnbalanced(self.events)) {
|
|
2501
|
-
effects.enter("literalAutolink");
|
|
2502
|
-
effects.enter("literalAutolinkHttp");
|
|
2503
|
-
buffer += String.fromCodePoint(code2);
|
|
2504
|
-
effects.consume(code2);
|
|
2505
|
-
return protocolPrefixInside;
|
|
2506
|
-
}
|
|
2507
|
-
return nok(code2);
|
|
2508
|
-
}
|
|
2509
|
-
function protocolPrefixInside(code2) {
|
|
2510
|
-
if (asciiAlpha(code2) && buffer.length < 5) {
|
|
2511
|
-
buffer += String.fromCodePoint(code2);
|
|
2512
|
-
effects.consume(code2);
|
|
2513
|
-
return protocolPrefixInside;
|
|
2514
|
-
}
|
|
2515
|
-
if (code2 === 58) {
|
|
2516
|
-
const protocol = buffer.toLowerCase();
|
|
2517
|
-
if (protocol === "http" || protocol === "https") {
|
|
2518
|
-
effects.consume(code2);
|
|
2519
|
-
return protocolSlashesInside;
|
|
2520
|
-
}
|
|
2521
|
-
}
|
|
2522
|
-
return nok(code2);
|
|
2523
|
-
}
|
|
2524
|
-
function protocolSlashesInside(code2) {
|
|
2525
|
-
if (code2 === 47) {
|
|
2526
|
-
effects.consume(code2);
|
|
2527
|
-
if (seen) {
|
|
2528
|
-
return afterProtocol;
|
|
2529
|
-
}
|
|
2530
|
-
seen = true;
|
|
2531
|
-
return protocolSlashesInside;
|
|
2532
|
-
}
|
|
2533
|
-
return nok(code2);
|
|
2534
|
-
}
|
|
2535
|
-
function afterProtocol(code2) {
|
|
2536
|
-
return code2 === null || asciiControl(code2) || markdownLineEndingOrSpace(code2) || unicodeWhitespace(code2) || unicodePunctuation(code2) ? nok(code2) : effects.attempt(domain, effects.attempt(path, protocolAfter), nok)(code2);
|
|
2537
|
-
}
|
|
2538
|
-
function protocolAfter(code2) {
|
|
2539
|
-
effects.exit("literalAutolinkHttp");
|
|
2540
|
-
effects.exit("literalAutolink");
|
|
2541
|
-
return ok2(code2);
|
|
2542
|
-
}
|
|
2543
|
-
}
|
|
2544
|
-
function tokenizeWwwPrefix(effects, ok2, nok) {
|
|
2545
|
-
let size = 0;
|
|
2546
|
-
return wwwPrefixInside;
|
|
2547
|
-
function wwwPrefixInside(code2) {
|
|
2548
|
-
if ((code2 === 87 || code2 === 119) && size < 3) {
|
|
2549
|
-
size++;
|
|
2550
|
-
effects.consume(code2);
|
|
2551
|
-
return wwwPrefixInside;
|
|
2552
|
-
}
|
|
2553
|
-
if (code2 === 46 && size === 3) {
|
|
2554
|
-
effects.consume(code2);
|
|
2555
|
-
return wwwPrefixAfter;
|
|
2556
|
-
}
|
|
2557
|
-
return nok(code2);
|
|
2558
|
-
}
|
|
2559
|
-
function wwwPrefixAfter(code2) {
|
|
2560
|
-
return code2 === null ? nok(code2) : ok2(code2);
|
|
2561
|
-
}
|
|
2562
|
-
}
|
|
2563
|
-
function tokenizeDomain(effects, ok2, nok) {
|
|
2564
|
-
let underscoreInLastSegment;
|
|
2565
|
-
let underscoreInLastLastSegment;
|
|
2566
|
-
let seen;
|
|
2567
|
-
return domainInside;
|
|
2568
|
-
function domainInside(code2) {
|
|
2569
|
-
if (code2 === 46 || code2 === 95) {
|
|
2570
|
-
return effects.check(trail, domainAfter, domainAtPunctuation)(code2);
|
|
2571
|
-
}
|
|
2572
|
-
if (code2 === null || markdownLineEndingOrSpace(code2) || unicodeWhitespace(code2) || code2 !== 45 && unicodePunctuation(code2)) {
|
|
2573
|
-
return domainAfter(code2);
|
|
2574
|
-
}
|
|
2575
|
-
seen = true;
|
|
2576
|
-
effects.consume(code2);
|
|
2577
|
-
return domainInside;
|
|
2578
|
-
}
|
|
2579
|
-
function domainAtPunctuation(code2) {
|
|
2580
|
-
if (code2 === 95) {
|
|
2581
|
-
underscoreInLastSegment = true;
|
|
2582
|
-
} else {
|
|
2583
|
-
underscoreInLastLastSegment = underscoreInLastSegment;
|
|
2584
|
-
underscoreInLastSegment = void 0;
|
|
2585
|
-
}
|
|
2586
|
-
effects.consume(code2);
|
|
2587
|
-
return domainInside;
|
|
2588
|
-
}
|
|
2589
|
-
function domainAfter(code2) {
|
|
2590
|
-
if (underscoreInLastLastSegment || underscoreInLastSegment || !seen) {
|
|
2591
|
-
return nok(code2);
|
|
2592
|
-
}
|
|
2593
|
-
return ok2(code2);
|
|
2594
|
-
}
|
|
2595
|
-
}
|
|
2596
|
-
function tokenizePath(effects, ok2) {
|
|
2597
|
-
let sizeOpen = 0;
|
|
2598
|
-
let sizeClose = 0;
|
|
2599
|
-
return pathInside;
|
|
2600
|
-
function pathInside(code2) {
|
|
2601
|
-
if (code2 === 40) {
|
|
2602
|
-
sizeOpen++;
|
|
2603
|
-
effects.consume(code2);
|
|
2604
|
-
return pathInside;
|
|
2605
|
-
}
|
|
2606
|
-
if (code2 === 41 && sizeClose < sizeOpen) {
|
|
2607
|
-
return pathAtPunctuation(code2);
|
|
2608
|
-
}
|
|
2609
|
-
if (code2 === 33 || code2 === 34 || code2 === 38 || code2 === 39 || code2 === 41 || code2 === 42 || code2 === 44 || code2 === 46 || code2 === 58 || code2 === 59 || code2 === 60 || code2 === 63 || code2 === 93 || code2 === 95 || code2 === 126) {
|
|
2610
|
-
return effects.check(trail, ok2, pathAtPunctuation)(code2);
|
|
2611
|
-
}
|
|
2612
|
-
if (code2 === null || markdownLineEndingOrSpace(code2) || unicodeWhitespace(code2)) {
|
|
2613
|
-
return ok2(code2);
|
|
2614
|
-
}
|
|
2615
|
-
effects.consume(code2);
|
|
2616
|
-
return pathInside;
|
|
2617
|
-
}
|
|
2618
|
-
function pathAtPunctuation(code2) {
|
|
2619
|
-
if (code2 === 41) {
|
|
2620
|
-
sizeClose++;
|
|
2621
|
-
}
|
|
2622
|
-
effects.consume(code2);
|
|
2623
|
-
return pathInside;
|
|
2624
|
-
}
|
|
2625
|
-
}
|
|
2626
|
-
function tokenizeTrail(effects, ok2, nok) {
|
|
2627
|
-
return trail2;
|
|
2628
|
-
function trail2(code2) {
|
|
2629
|
-
if (code2 === 33 || code2 === 34 || code2 === 39 || code2 === 41 || code2 === 42 || code2 === 44 || code2 === 46 || code2 === 58 || code2 === 59 || code2 === 63 || code2 === 95 || code2 === 126) {
|
|
2630
|
-
effects.consume(code2);
|
|
2631
|
-
return trail2;
|
|
2632
|
-
}
|
|
2633
|
-
if (code2 === 38) {
|
|
2634
|
-
effects.consume(code2);
|
|
2635
|
-
return trailCharacterReferenceStart;
|
|
2636
|
-
}
|
|
2637
|
-
if (code2 === 93) {
|
|
2638
|
-
effects.consume(code2);
|
|
2639
|
-
return trailBracketAfter;
|
|
2640
|
-
}
|
|
2641
|
-
if (
|
|
2642
|
-
// `<` is an end.
|
|
2643
|
-
code2 === 60 || // So is whitespace.
|
|
2644
|
-
code2 === null || markdownLineEndingOrSpace(code2) || unicodeWhitespace(code2)
|
|
2645
|
-
) {
|
|
2646
|
-
return ok2(code2);
|
|
2647
|
-
}
|
|
2648
|
-
return nok(code2);
|
|
2649
|
-
}
|
|
2650
|
-
function trailBracketAfter(code2) {
|
|
2651
|
-
if (code2 === null || code2 === 40 || code2 === 91 || markdownLineEndingOrSpace(code2) || unicodeWhitespace(code2)) {
|
|
2652
|
-
return ok2(code2);
|
|
2653
|
-
}
|
|
2654
|
-
return trail2(code2);
|
|
2655
|
-
}
|
|
2656
|
-
function trailCharacterReferenceStart(code2) {
|
|
2657
|
-
return asciiAlpha(code2) ? trailCharacterReferenceInside(code2) : nok(code2);
|
|
2658
|
-
}
|
|
2659
|
-
function trailCharacterReferenceInside(code2) {
|
|
2660
|
-
if (code2 === 59) {
|
|
2661
|
-
effects.consume(code2);
|
|
2662
|
-
return trail2;
|
|
2663
|
-
}
|
|
2664
|
-
if (asciiAlpha(code2)) {
|
|
2665
|
-
effects.consume(code2);
|
|
2666
|
-
return trailCharacterReferenceInside;
|
|
2667
|
-
}
|
|
2668
|
-
return nok(code2);
|
|
2669
|
-
}
|
|
2670
|
-
}
|
|
2671
|
-
function tokenizeEmailDomainDotTrail(effects, ok2, nok) {
|
|
2672
|
-
return start;
|
|
2673
|
-
function start(code2) {
|
|
2674
|
-
effects.consume(code2);
|
|
2675
|
-
return after;
|
|
2676
|
-
}
|
|
2677
|
-
function after(code2) {
|
|
2678
|
-
return asciiAlphanumeric(code2) ? nok(code2) : ok2(code2);
|
|
2679
|
-
}
|
|
2680
|
-
}
|
|
2681
|
-
function previousWww(code2) {
|
|
2682
|
-
return code2 === null || code2 === 40 || code2 === 42 || code2 === 95 || code2 === 91 || code2 === 93 || code2 === 126 || markdownLineEndingOrSpace(code2);
|
|
2683
|
-
}
|
|
2684
|
-
function previousProtocol(code2) {
|
|
2685
|
-
return !asciiAlpha(code2);
|
|
2686
|
-
}
|
|
2687
|
-
function previousEmail(code2) {
|
|
2688
|
-
return !(code2 === 47 || gfmAtext(code2));
|
|
2689
|
-
}
|
|
2690
|
-
function gfmAtext(code2) {
|
|
2691
|
-
return code2 === 43 || code2 === 45 || code2 === 46 || code2 === 95 || asciiAlphanumeric(code2);
|
|
2692
|
-
}
|
|
2693
|
-
function previousUnbalanced(events) {
|
|
2694
|
-
let index = events.length;
|
|
2695
|
-
let result = false;
|
|
2696
|
-
while (index--) {
|
|
2697
|
-
const token = events[index][1];
|
|
2698
|
-
if ((token.type === "labelLink" || token.type === "labelImage") && !token._balanced) {
|
|
2699
|
-
result = true;
|
|
2700
|
-
break;
|
|
2701
|
-
}
|
|
2702
|
-
if (token._gfmAutolinkLiteralWalkedInto) {
|
|
2703
|
-
result = false;
|
|
2704
|
-
break;
|
|
2705
|
-
}
|
|
2706
|
-
}
|
|
2707
|
-
if (events.length > 0 && !result) {
|
|
2708
|
-
events[events.length - 1][1]._gfmAutolinkLiteralWalkedInto = true;
|
|
2709
|
-
}
|
|
2710
|
-
return result;
|
|
2711
|
-
}
|
|
2712
|
-
function resolveAll(constructs2, events, context) {
|
|
2713
|
-
const called = [];
|
|
2714
|
-
let index = -1;
|
|
2715
|
-
while (++index < constructs2.length) {
|
|
2716
|
-
const resolve = constructs2[index].resolveAll;
|
|
2717
|
-
if (resolve && !called.includes(resolve)) {
|
|
2718
|
-
events = resolve(events, context);
|
|
2719
|
-
called.push(resolve);
|
|
2720
|
-
}
|
|
2721
|
-
}
|
|
2722
|
-
return events;
|
|
2723
|
-
}
|
|
2724
|
-
function factorySpace(effects, ok2, type, max) {
|
|
2725
|
-
const limit = max ? max - 1 : Number.POSITIVE_INFINITY;
|
|
2726
|
-
let size = 0;
|
|
2727
|
-
return start;
|
|
2728
|
-
function start(code2) {
|
|
2729
|
-
if (markdownSpace(code2)) {
|
|
2730
|
-
effects.enter(type);
|
|
2731
|
-
return prefix(code2);
|
|
2732
|
-
}
|
|
2733
|
-
return ok2(code2);
|
|
2734
|
-
}
|
|
2735
|
-
function prefix(code2) {
|
|
2736
|
-
if (markdownSpace(code2) && size++ < limit) {
|
|
2737
|
-
effects.consume(code2);
|
|
2738
|
-
return prefix;
|
|
2739
|
-
}
|
|
2740
|
-
effects.exit(type);
|
|
2741
|
-
return ok2(code2);
|
|
2742
|
-
}
|
|
2743
|
-
}
|
|
2744
|
-
const blankLine = {
|
|
2745
|
-
partial: true,
|
|
2746
|
-
tokenize: tokenizeBlankLine
|
|
2747
|
-
};
|
|
2748
|
-
function tokenizeBlankLine(effects, ok2, nok) {
|
|
2749
|
-
return start;
|
|
2750
|
-
function start(code2) {
|
|
2751
|
-
return markdownSpace(code2) ? factorySpace(effects, after, "linePrefix")(code2) : after(code2);
|
|
2752
|
-
}
|
|
2753
|
-
function after(code2) {
|
|
2754
|
-
return code2 === null || markdownLineEnding(code2) ? ok2(code2) : nok(code2);
|
|
2755
|
-
}
|
|
2756
|
-
}
|
|
2757
|
-
const indent = {
|
|
2758
|
-
tokenize: tokenizeIndent,
|
|
2759
|
-
partial: true
|
|
2760
|
-
};
|
|
2761
|
-
function gfmFootnote() {
|
|
2762
|
-
return {
|
|
2763
|
-
document: {
|
|
2764
|
-
[91]: {
|
|
2765
|
-
name: "gfmFootnoteDefinition",
|
|
2766
|
-
tokenize: tokenizeDefinitionStart,
|
|
2767
|
-
continuation: {
|
|
2768
|
-
tokenize: tokenizeDefinitionContinuation
|
|
2769
|
-
},
|
|
2770
|
-
exit: gfmFootnoteDefinitionEnd
|
|
2771
|
-
}
|
|
2772
|
-
},
|
|
2773
|
-
text: {
|
|
2774
|
-
[91]: {
|
|
2775
|
-
name: "gfmFootnoteCall",
|
|
2776
|
-
tokenize: tokenizeGfmFootnoteCall
|
|
2777
|
-
},
|
|
2778
|
-
[93]: {
|
|
2779
|
-
name: "gfmPotentialFootnoteCall",
|
|
2780
|
-
add: "after",
|
|
2781
|
-
tokenize: tokenizePotentialGfmFootnoteCall,
|
|
2782
|
-
resolveTo: resolveToPotentialGfmFootnoteCall
|
|
2783
|
-
}
|
|
2784
|
-
}
|
|
2785
|
-
};
|
|
2786
|
-
}
|
|
2787
|
-
function tokenizePotentialGfmFootnoteCall(effects, ok2, nok) {
|
|
2788
|
-
const self = this;
|
|
2789
|
-
let index = self.events.length;
|
|
2790
|
-
const defined = self.parser.gfmFootnotes || (self.parser.gfmFootnotes = []);
|
|
2791
|
-
let labelStart;
|
|
2792
|
-
while (index--) {
|
|
2793
|
-
const token = self.events[index][1];
|
|
2794
|
-
if (token.type === "labelImage") {
|
|
2795
|
-
labelStart = token;
|
|
2796
|
-
break;
|
|
2797
|
-
}
|
|
2798
|
-
if (token.type === "gfmFootnoteCall" || token.type === "labelLink" || token.type === "label" || token.type === "image" || token.type === "link") {
|
|
2799
|
-
break;
|
|
2800
|
-
}
|
|
2801
|
-
}
|
|
2802
|
-
return start;
|
|
2803
|
-
function start(code2) {
|
|
2804
|
-
if (!labelStart || !labelStart._balanced) {
|
|
2805
|
-
return nok(code2);
|
|
2806
|
-
}
|
|
2807
|
-
const id = normalizeIdentifier(self.sliceSerialize({
|
|
2808
|
-
start: labelStart.end,
|
|
2809
|
-
end: self.now()
|
|
2810
|
-
}));
|
|
2811
|
-
if (id.codePointAt(0) !== 94 || !defined.includes(id.slice(1))) {
|
|
2812
|
-
return nok(code2);
|
|
2813
|
-
}
|
|
2814
|
-
effects.enter("gfmFootnoteCallLabelMarker");
|
|
2815
|
-
effects.consume(code2);
|
|
2816
|
-
effects.exit("gfmFootnoteCallLabelMarker");
|
|
2817
|
-
return ok2(code2);
|
|
2818
|
-
}
|
|
2819
|
-
}
|
|
2820
|
-
function resolveToPotentialGfmFootnoteCall(events, context) {
|
|
2821
|
-
let index = events.length;
|
|
2822
|
-
while (index--) {
|
|
2823
|
-
if (events[index][1].type === "labelImage" && events[index][0] === "enter") {
|
|
2824
|
-
events[index][1];
|
|
2825
|
-
break;
|
|
2826
|
-
}
|
|
2827
|
-
}
|
|
2828
|
-
events[index + 1][1].type = "data";
|
|
2829
|
-
events[index + 3][1].type = "gfmFootnoteCallLabelMarker";
|
|
2830
|
-
const call = {
|
|
2831
|
-
type: "gfmFootnoteCall",
|
|
2832
|
-
start: Object.assign({}, events[index + 3][1].start),
|
|
2833
|
-
end: Object.assign({}, events[events.length - 1][1].end)
|
|
2834
|
-
};
|
|
2835
|
-
const marker = {
|
|
2836
|
-
type: "gfmFootnoteCallMarker",
|
|
2837
|
-
start: Object.assign({}, events[index + 3][1].end),
|
|
2838
|
-
end: Object.assign({}, events[index + 3][1].end)
|
|
2839
|
-
};
|
|
2840
|
-
marker.end.column++;
|
|
2841
|
-
marker.end.offset++;
|
|
2842
|
-
marker.end._bufferIndex++;
|
|
2843
|
-
const string = {
|
|
2844
|
-
type: "gfmFootnoteCallString",
|
|
2845
|
-
start: Object.assign({}, marker.end),
|
|
2846
|
-
end: Object.assign({}, events[events.length - 1][1].start)
|
|
2847
|
-
};
|
|
2848
|
-
const chunk = {
|
|
2849
|
-
type: "chunkString",
|
|
2850
|
-
contentType: "string",
|
|
2851
|
-
start: Object.assign({}, string.start),
|
|
2852
|
-
end: Object.assign({}, string.end)
|
|
2853
|
-
};
|
|
2854
|
-
const replacement = [
|
|
2855
|
-
// Take the `labelImageMarker` (now `data`, the `!`)
|
|
2856
|
-
events[index + 1],
|
|
2857
|
-
events[index + 2],
|
|
2858
|
-
["enter", call, context],
|
|
2859
|
-
// The `[`
|
|
2860
|
-
events[index + 3],
|
|
2861
|
-
events[index + 4],
|
|
2862
|
-
// The `^`.
|
|
2863
|
-
["enter", marker, context],
|
|
2864
|
-
["exit", marker, context],
|
|
2865
|
-
// Everything in between.
|
|
2866
|
-
["enter", string, context],
|
|
2867
|
-
["enter", chunk, context],
|
|
2868
|
-
["exit", chunk, context],
|
|
2869
|
-
["exit", string, context],
|
|
2870
|
-
// The ending (`]`, properly parsed and labelled).
|
|
2871
|
-
events[events.length - 2],
|
|
2872
|
-
events[events.length - 1],
|
|
2873
|
-
["exit", call, context]
|
|
2874
|
-
];
|
|
2875
|
-
events.splice(index, events.length - index + 1, ...replacement);
|
|
2876
|
-
return events;
|
|
2877
|
-
}
|
|
2878
|
-
function tokenizeGfmFootnoteCall(effects, ok2, nok) {
|
|
2879
|
-
const self = this;
|
|
2880
|
-
const defined = self.parser.gfmFootnotes || (self.parser.gfmFootnotes = []);
|
|
2881
|
-
let size = 0;
|
|
2882
|
-
let data;
|
|
2883
|
-
return start;
|
|
2884
|
-
function start(code2) {
|
|
2885
|
-
effects.enter("gfmFootnoteCall");
|
|
2886
|
-
effects.enter("gfmFootnoteCallLabelMarker");
|
|
2887
|
-
effects.consume(code2);
|
|
2888
|
-
effects.exit("gfmFootnoteCallLabelMarker");
|
|
2889
|
-
return callStart;
|
|
2890
|
-
}
|
|
2891
|
-
function callStart(code2) {
|
|
2892
|
-
if (code2 !== 94) return nok(code2);
|
|
2893
|
-
effects.enter("gfmFootnoteCallMarker");
|
|
2894
|
-
effects.consume(code2);
|
|
2895
|
-
effects.exit("gfmFootnoteCallMarker");
|
|
2896
|
-
effects.enter("gfmFootnoteCallString");
|
|
2897
|
-
effects.enter("chunkString").contentType = "string";
|
|
2898
|
-
return callData;
|
|
2899
|
-
}
|
|
2900
|
-
function callData(code2) {
|
|
2901
|
-
if (
|
|
2902
|
-
// Too long.
|
|
2903
|
-
size > 999 || // Closing brace with nothing.
|
|
2904
|
-
code2 === 93 && !data || // Space or tab is not supported by GFM for some reason.
|
|
2905
|
-
// `\n` and `[` not being supported makes sense.
|
|
2906
|
-
code2 === null || code2 === 91 || markdownLineEndingOrSpace(code2)
|
|
2907
|
-
) {
|
|
2908
|
-
return nok(code2);
|
|
2909
|
-
}
|
|
2910
|
-
if (code2 === 93) {
|
|
2911
|
-
effects.exit("chunkString");
|
|
2912
|
-
const token = effects.exit("gfmFootnoteCallString");
|
|
2913
|
-
if (!defined.includes(normalizeIdentifier(self.sliceSerialize(token)))) {
|
|
2914
|
-
return nok(code2);
|
|
2915
|
-
}
|
|
2916
|
-
effects.enter("gfmFootnoteCallLabelMarker");
|
|
2917
|
-
effects.consume(code2);
|
|
2918
|
-
effects.exit("gfmFootnoteCallLabelMarker");
|
|
2919
|
-
effects.exit("gfmFootnoteCall");
|
|
2920
|
-
return ok2;
|
|
2921
|
-
}
|
|
2922
|
-
if (!markdownLineEndingOrSpace(code2)) {
|
|
2923
|
-
data = true;
|
|
2924
|
-
}
|
|
2925
|
-
size++;
|
|
2926
|
-
effects.consume(code2);
|
|
2927
|
-
return code2 === 92 ? callEscape : callData;
|
|
2928
|
-
}
|
|
2929
|
-
function callEscape(code2) {
|
|
2930
|
-
if (code2 === 91 || code2 === 92 || code2 === 93) {
|
|
2931
|
-
effects.consume(code2);
|
|
2932
|
-
size++;
|
|
2933
|
-
return callData;
|
|
2934
|
-
}
|
|
2935
|
-
return callData(code2);
|
|
2936
|
-
}
|
|
2937
|
-
}
|
|
2938
|
-
function tokenizeDefinitionStart(effects, ok2, nok) {
|
|
2939
|
-
const self = this;
|
|
2940
|
-
const defined = self.parser.gfmFootnotes || (self.parser.gfmFootnotes = []);
|
|
2941
|
-
let identifier;
|
|
2942
|
-
let size = 0;
|
|
2943
|
-
let data;
|
|
2944
|
-
return start;
|
|
2945
|
-
function start(code2) {
|
|
2946
|
-
effects.enter("gfmFootnoteDefinition")._container = true;
|
|
2947
|
-
effects.enter("gfmFootnoteDefinitionLabel");
|
|
2948
|
-
effects.enter("gfmFootnoteDefinitionLabelMarker");
|
|
2949
|
-
effects.consume(code2);
|
|
2950
|
-
effects.exit("gfmFootnoteDefinitionLabelMarker");
|
|
2951
|
-
return labelAtMarker;
|
|
2952
|
-
}
|
|
2953
|
-
function labelAtMarker(code2) {
|
|
2954
|
-
if (code2 === 94) {
|
|
2955
|
-
effects.enter("gfmFootnoteDefinitionMarker");
|
|
2956
|
-
effects.consume(code2);
|
|
2957
|
-
effects.exit("gfmFootnoteDefinitionMarker");
|
|
2958
|
-
effects.enter("gfmFootnoteDefinitionLabelString");
|
|
2959
|
-
effects.enter("chunkString").contentType = "string";
|
|
2960
|
-
return labelInside;
|
|
2961
|
-
}
|
|
2962
|
-
return nok(code2);
|
|
2963
|
-
}
|
|
2964
|
-
function labelInside(code2) {
|
|
2965
|
-
if (
|
|
2966
|
-
// Too long.
|
|
2967
|
-
size > 999 || // Closing brace with nothing.
|
|
2968
|
-
code2 === 93 && !data || // Space or tab is not supported by GFM for some reason.
|
|
2969
|
-
// `\n` and `[` not being supported makes sense.
|
|
2970
|
-
code2 === null || code2 === 91 || markdownLineEndingOrSpace(code2)
|
|
2971
|
-
) {
|
|
2972
|
-
return nok(code2);
|
|
2973
|
-
}
|
|
2974
|
-
if (code2 === 93) {
|
|
2975
|
-
effects.exit("chunkString");
|
|
2976
|
-
const token = effects.exit("gfmFootnoteDefinitionLabelString");
|
|
2977
|
-
identifier = normalizeIdentifier(self.sliceSerialize(token));
|
|
2978
|
-
effects.enter("gfmFootnoteDefinitionLabelMarker");
|
|
2979
|
-
effects.consume(code2);
|
|
2980
|
-
effects.exit("gfmFootnoteDefinitionLabelMarker");
|
|
2981
|
-
effects.exit("gfmFootnoteDefinitionLabel");
|
|
2982
|
-
return labelAfter;
|
|
2983
|
-
}
|
|
2984
|
-
if (!markdownLineEndingOrSpace(code2)) {
|
|
2985
|
-
data = true;
|
|
2986
|
-
}
|
|
2987
|
-
size++;
|
|
2988
|
-
effects.consume(code2);
|
|
2989
|
-
return code2 === 92 ? labelEscape : labelInside;
|
|
2990
|
-
}
|
|
2991
|
-
function labelEscape(code2) {
|
|
2992
|
-
if (code2 === 91 || code2 === 92 || code2 === 93) {
|
|
2993
|
-
effects.consume(code2);
|
|
2994
|
-
size++;
|
|
2995
|
-
return labelInside;
|
|
2996
|
-
}
|
|
2997
|
-
return labelInside(code2);
|
|
2998
|
-
}
|
|
2999
|
-
function labelAfter(code2) {
|
|
3000
|
-
if (code2 === 58) {
|
|
3001
|
-
effects.enter("definitionMarker");
|
|
3002
|
-
effects.consume(code2);
|
|
3003
|
-
effects.exit("definitionMarker");
|
|
3004
|
-
if (!defined.includes(identifier)) {
|
|
3005
|
-
defined.push(identifier);
|
|
3006
|
-
}
|
|
3007
|
-
return factorySpace(effects, whitespaceAfter, "gfmFootnoteDefinitionWhitespace");
|
|
3008
|
-
}
|
|
3009
|
-
return nok(code2);
|
|
3010
|
-
}
|
|
3011
|
-
function whitespaceAfter(code2) {
|
|
3012
|
-
return ok2(code2);
|
|
3013
|
-
}
|
|
3014
|
-
}
|
|
3015
|
-
function tokenizeDefinitionContinuation(effects, ok2, nok) {
|
|
3016
|
-
return effects.check(blankLine, ok2, effects.attempt(indent, ok2, nok));
|
|
3017
|
-
}
|
|
3018
|
-
function gfmFootnoteDefinitionEnd(effects) {
|
|
3019
|
-
effects.exit("gfmFootnoteDefinition");
|
|
3020
|
-
}
|
|
3021
|
-
function tokenizeIndent(effects, ok2, nok) {
|
|
3022
|
-
const self = this;
|
|
3023
|
-
return factorySpace(effects, afterPrefix, "gfmFootnoteDefinitionIndent", 4 + 1);
|
|
3024
|
-
function afterPrefix(code2) {
|
|
3025
|
-
const tail = self.events[self.events.length - 1];
|
|
3026
|
-
return tail && tail[1].type === "gfmFootnoteDefinitionIndent" && tail[2].sliceSerialize(tail[1], true).length === 4 ? ok2(code2) : nok(code2);
|
|
3027
|
-
}
|
|
3028
|
-
}
|
|
3029
|
-
function gfmStrikethrough(options) {
|
|
3030
|
-
const options_ = options || {};
|
|
3031
|
-
let single = options_.singleTilde;
|
|
3032
|
-
const tokenizer = {
|
|
3033
|
-
name: "strikethrough",
|
|
3034
|
-
tokenize: tokenizeStrikethrough,
|
|
3035
|
-
resolveAll: resolveAllStrikethrough
|
|
3036
|
-
};
|
|
3037
|
-
if (single === null || single === void 0) {
|
|
3038
|
-
single = true;
|
|
3039
|
-
}
|
|
3040
|
-
return {
|
|
3041
|
-
text: {
|
|
3042
|
-
[126]: tokenizer
|
|
3043
|
-
},
|
|
3044
|
-
insideSpan: {
|
|
3045
|
-
null: [tokenizer]
|
|
3046
|
-
},
|
|
3047
|
-
attentionMarkers: {
|
|
3048
|
-
null: [126]
|
|
3049
|
-
}
|
|
3050
|
-
};
|
|
3051
|
-
function resolveAllStrikethrough(events, context) {
|
|
3052
|
-
let index = -1;
|
|
3053
|
-
while (++index < events.length) {
|
|
3054
|
-
if (events[index][0] === "enter" && events[index][1].type === "strikethroughSequenceTemporary" && events[index][1]._close) {
|
|
3055
|
-
let open = index;
|
|
3056
|
-
while (open--) {
|
|
3057
|
-
if (events[open][0] === "exit" && events[open][1].type === "strikethroughSequenceTemporary" && events[open][1]._open && // If the sizes are the same:
|
|
3058
|
-
events[index][1].end.offset - events[index][1].start.offset === events[open][1].end.offset - events[open][1].start.offset) {
|
|
3059
|
-
events[index][1].type = "strikethroughSequence";
|
|
3060
|
-
events[open][1].type = "strikethroughSequence";
|
|
3061
|
-
const strikethrough = {
|
|
3062
|
-
type: "strikethrough",
|
|
3063
|
-
start: Object.assign({}, events[open][1].start),
|
|
3064
|
-
end: Object.assign({}, events[index][1].end)
|
|
3065
|
-
};
|
|
3066
|
-
const text2 = {
|
|
3067
|
-
type: "strikethroughText",
|
|
3068
|
-
start: Object.assign({}, events[open][1].end),
|
|
3069
|
-
end: Object.assign({}, events[index][1].start)
|
|
3070
|
-
};
|
|
3071
|
-
const nextEvents = [["enter", strikethrough, context], ["enter", events[open][1], context], ["exit", events[open][1], context], ["enter", text2, context]];
|
|
3072
|
-
const insideSpan = context.parser.constructs.insideSpan.null;
|
|
3073
|
-
if (insideSpan) {
|
|
3074
|
-
splice(nextEvents, nextEvents.length, 0, resolveAll(insideSpan, events.slice(open + 1, index), context));
|
|
3075
|
-
}
|
|
3076
|
-
splice(nextEvents, nextEvents.length, 0, [["exit", text2, context], ["enter", events[index][1], context], ["exit", events[index][1], context], ["exit", strikethrough, context]]);
|
|
3077
|
-
splice(events, open - 1, index - open + 3, nextEvents);
|
|
3078
|
-
index = open + nextEvents.length - 2;
|
|
3079
|
-
break;
|
|
3080
|
-
}
|
|
3081
|
-
}
|
|
3082
|
-
}
|
|
3083
|
-
}
|
|
3084
|
-
index = -1;
|
|
3085
|
-
while (++index < events.length) {
|
|
3086
|
-
if (events[index][1].type === "strikethroughSequenceTemporary") {
|
|
3087
|
-
events[index][1].type = "data";
|
|
3088
|
-
}
|
|
3089
|
-
}
|
|
3090
|
-
return events;
|
|
3091
|
-
}
|
|
3092
|
-
function tokenizeStrikethrough(effects, ok2, nok) {
|
|
3093
|
-
const previous2 = this.previous;
|
|
3094
|
-
const events = this.events;
|
|
3095
|
-
let size = 0;
|
|
3096
|
-
return start;
|
|
3097
|
-
function start(code2) {
|
|
3098
|
-
if (previous2 === 126 && events[events.length - 1][1].type !== "characterEscape") {
|
|
3099
|
-
return nok(code2);
|
|
3100
|
-
}
|
|
3101
|
-
effects.enter("strikethroughSequenceTemporary");
|
|
3102
|
-
return more(code2);
|
|
3103
|
-
}
|
|
3104
|
-
function more(code2) {
|
|
3105
|
-
const before = classifyCharacter(previous2);
|
|
3106
|
-
if (code2 === 126) {
|
|
3107
|
-
if (size > 1) return nok(code2);
|
|
3108
|
-
effects.consume(code2);
|
|
3109
|
-
size++;
|
|
3110
|
-
return more;
|
|
3111
|
-
}
|
|
3112
|
-
if (size < 2 && !single) return nok(code2);
|
|
3113
|
-
const token = effects.exit("strikethroughSequenceTemporary");
|
|
3114
|
-
const after = classifyCharacter(code2);
|
|
3115
|
-
token._open = !after || after === 2 && Boolean(before);
|
|
3116
|
-
token._close = !before || before === 2 && Boolean(after);
|
|
3117
|
-
return ok2(code2);
|
|
3118
|
-
}
|
|
3119
|
-
}
|
|
3120
|
-
}
|
|
3121
|
-
class EditMap {
|
|
3122
|
-
/**
|
|
3123
|
-
* Create a new edit map.
|
|
3124
|
-
*/
|
|
3125
|
-
constructor() {
|
|
3126
|
-
this.map = [];
|
|
3127
|
-
}
|
|
3128
|
-
/**
|
|
3129
|
-
* Create an edit: a remove and/or add at a certain place.
|
|
3130
|
-
*
|
|
3131
|
-
* @param {number} index
|
|
3132
|
-
* @param {number} remove
|
|
3133
|
-
* @param {Array<Event>} add
|
|
3134
|
-
* @returns {undefined}
|
|
3135
|
-
*/
|
|
3136
|
-
add(index, remove, add) {
|
|
3137
|
-
addImplementation(this, index, remove, add);
|
|
3138
|
-
}
|
|
3139
|
-
// To do: add this when moving to `micromark`.
|
|
3140
|
-
// /**
|
|
3141
|
-
// * Create an edit: but insert `add` before existing additions.
|
|
3142
|
-
// *
|
|
3143
|
-
// * @param {number} index
|
|
3144
|
-
// * @param {number} remove
|
|
3145
|
-
// * @param {Array<Event>} add
|
|
3146
|
-
// * @returns {undefined}
|
|
3147
|
-
// */
|
|
3148
|
-
// addBefore(index, remove, add) {
|
|
3149
|
-
// addImplementation(this, index, remove, add, true)
|
|
3150
|
-
// }
|
|
3151
|
-
/**
|
|
3152
|
-
* Done, change the events.
|
|
3153
|
-
*
|
|
3154
|
-
* @param {Array<Event>} events
|
|
3155
|
-
* @returns {undefined}
|
|
3156
|
-
*/
|
|
3157
|
-
consume(events) {
|
|
3158
|
-
this.map.sort(function(a, b) {
|
|
3159
|
-
return a[0] - b[0];
|
|
3160
|
-
});
|
|
3161
|
-
if (this.map.length === 0) {
|
|
3162
|
-
return;
|
|
3163
|
-
}
|
|
3164
|
-
let index = this.map.length;
|
|
3165
|
-
const vecs = [];
|
|
3166
|
-
while (index > 0) {
|
|
3167
|
-
index -= 1;
|
|
3168
|
-
vecs.push(events.slice(this.map[index][0] + this.map[index][1]), this.map[index][2]);
|
|
3169
|
-
events.length = this.map[index][0];
|
|
3170
|
-
}
|
|
3171
|
-
vecs.push(events.slice());
|
|
3172
|
-
events.length = 0;
|
|
3173
|
-
let slice = vecs.pop();
|
|
3174
|
-
while (slice) {
|
|
3175
|
-
for (const element of slice) {
|
|
3176
|
-
events.push(element);
|
|
3177
|
-
}
|
|
3178
|
-
slice = vecs.pop();
|
|
3179
|
-
}
|
|
3180
|
-
this.map.length = 0;
|
|
3181
|
-
}
|
|
3182
|
-
}
|
|
3183
|
-
function addImplementation(editMap, at, remove, add) {
|
|
3184
|
-
let index = 0;
|
|
3185
|
-
if (remove === 0 && add.length === 0) {
|
|
3186
|
-
return;
|
|
3187
|
-
}
|
|
3188
|
-
while (index < editMap.map.length) {
|
|
3189
|
-
if (editMap.map[index][0] === at) {
|
|
3190
|
-
editMap.map[index][1] += remove;
|
|
3191
|
-
editMap.map[index][2].push(...add);
|
|
3192
|
-
return;
|
|
3193
|
-
}
|
|
3194
|
-
index += 1;
|
|
3195
|
-
}
|
|
3196
|
-
editMap.map.push([at, remove, add]);
|
|
3197
|
-
}
|
|
3198
|
-
function gfmTableAlign(events, index) {
|
|
3199
|
-
let inDelimiterRow = false;
|
|
3200
|
-
const align = [];
|
|
3201
|
-
while (index < events.length) {
|
|
3202
|
-
const event = events[index];
|
|
3203
|
-
if (inDelimiterRow) {
|
|
3204
|
-
if (event[0] === "enter") {
|
|
3205
|
-
if (event[1].type === "tableContent") {
|
|
3206
|
-
align.push(events[index + 1][1].type === "tableDelimiterMarker" ? "left" : "none");
|
|
3207
|
-
}
|
|
3208
|
-
} else if (event[1].type === "tableContent") {
|
|
3209
|
-
if (events[index - 1][1].type === "tableDelimiterMarker") {
|
|
3210
|
-
const alignIndex = align.length - 1;
|
|
3211
|
-
align[alignIndex] = align[alignIndex] === "left" ? "center" : "right";
|
|
3212
|
-
}
|
|
3213
|
-
} else if (event[1].type === "tableDelimiterRow") {
|
|
3214
|
-
break;
|
|
3215
|
-
}
|
|
3216
|
-
} else if (event[0] === "enter" && event[1].type === "tableDelimiterRow") {
|
|
3217
|
-
inDelimiterRow = true;
|
|
3218
|
-
}
|
|
3219
|
-
index += 1;
|
|
3220
|
-
}
|
|
3221
|
-
return align;
|
|
3222
|
-
}
|
|
3223
|
-
function gfmTable() {
|
|
3224
|
-
return {
|
|
3225
|
-
flow: {
|
|
3226
|
-
null: {
|
|
3227
|
-
name: "table",
|
|
3228
|
-
tokenize: tokenizeTable,
|
|
3229
|
-
resolveAll: resolveTable
|
|
3230
|
-
}
|
|
3231
|
-
}
|
|
3232
|
-
};
|
|
3233
|
-
}
|
|
3234
|
-
function tokenizeTable(effects, ok2, nok) {
|
|
3235
|
-
const self = this;
|
|
3236
|
-
let size = 0;
|
|
3237
|
-
let sizeB = 0;
|
|
3238
|
-
let seen;
|
|
3239
|
-
return start;
|
|
3240
|
-
function start(code2) {
|
|
3241
|
-
let index = self.events.length - 1;
|
|
3242
|
-
while (index > -1) {
|
|
3243
|
-
const type = self.events[index][1].type;
|
|
3244
|
-
if (type === "lineEnding" || // Note: markdown-rs uses `whitespace` instead of `linePrefix`
|
|
3245
|
-
type === "linePrefix") index--;
|
|
3246
|
-
else break;
|
|
3247
|
-
}
|
|
3248
|
-
const tail = index > -1 ? self.events[index][1].type : null;
|
|
3249
|
-
const next = tail === "tableHead" || tail === "tableRow" ? bodyRowStart : headRowBefore;
|
|
3250
|
-
if (next === bodyRowStart && self.parser.lazy[self.now().line]) {
|
|
3251
|
-
return nok(code2);
|
|
3252
|
-
}
|
|
3253
|
-
return next(code2);
|
|
3254
|
-
}
|
|
3255
|
-
function headRowBefore(code2) {
|
|
3256
|
-
effects.enter("tableHead");
|
|
3257
|
-
effects.enter("tableRow");
|
|
3258
|
-
return headRowStart(code2);
|
|
3259
|
-
}
|
|
3260
|
-
function headRowStart(code2) {
|
|
3261
|
-
if (code2 === 124) {
|
|
3262
|
-
return headRowBreak(code2);
|
|
3263
|
-
}
|
|
3264
|
-
seen = true;
|
|
3265
|
-
sizeB += 1;
|
|
3266
|
-
return headRowBreak(code2);
|
|
3267
|
-
}
|
|
3268
|
-
function headRowBreak(code2) {
|
|
3269
|
-
if (code2 === null) {
|
|
3270
|
-
return nok(code2);
|
|
3271
|
-
}
|
|
3272
|
-
if (markdownLineEnding(code2)) {
|
|
3273
|
-
if (sizeB > 1) {
|
|
3274
|
-
sizeB = 0;
|
|
3275
|
-
self.interrupt = true;
|
|
3276
|
-
effects.exit("tableRow");
|
|
3277
|
-
effects.enter("lineEnding");
|
|
3278
|
-
effects.consume(code2);
|
|
3279
|
-
effects.exit("lineEnding");
|
|
3280
|
-
return headDelimiterStart;
|
|
3281
|
-
}
|
|
3282
|
-
return nok(code2);
|
|
3283
|
-
}
|
|
3284
|
-
if (markdownSpace(code2)) {
|
|
3285
|
-
return factorySpace(effects, headRowBreak, "whitespace")(code2);
|
|
3286
|
-
}
|
|
3287
|
-
sizeB += 1;
|
|
3288
|
-
if (seen) {
|
|
3289
|
-
seen = false;
|
|
3290
|
-
size += 1;
|
|
3291
|
-
}
|
|
3292
|
-
if (code2 === 124) {
|
|
3293
|
-
effects.enter("tableCellDivider");
|
|
3294
|
-
effects.consume(code2);
|
|
3295
|
-
effects.exit("tableCellDivider");
|
|
3296
|
-
seen = true;
|
|
3297
|
-
return headRowBreak;
|
|
3298
|
-
}
|
|
3299
|
-
effects.enter("data");
|
|
3300
|
-
return headRowData(code2);
|
|
3301
|
-
}
|
|
3302
|
-
function headRowData(code2) {
|
|
3303
|
-
if (code2 === null || code2 === 124 || markdownLineEndingOrSpace(code2)) {
|
|
3304
|
-
effects.exit("data");
|
|
3305
|
-
return headRowBreak(code2);
|
|
3306
|
-
}
|
|
3307
|
-
effects.consume(code2);
|
|
3308
|
-
return code2 === 92 ? headRowEscape : headRowData;
|
|
3309
|
-
}
|
|
3310
|
-
function headRowEscape(code2) {
|
|
3311
|
-
if (code2 === 92 || code2 === 124) {
|
|
3312
|
-
effects.consume(code2);
|
|
3313
|
-
return headRowData;
|
|
3314
|
-
}
|
|
3315
|
-
return headRowData(code2);
|
|
3316
|
-
}
|
|
3317
|
-
function headDelimiterStart(code2) {
|
|
3318
|
-
self.interrupt = false;
|
|
3319
|
-
if (self.parser.lazy[self.now().line]) {
|
|
3320
|
-
return nok(code2);
|
|
3321
|
-
}
|
|
3322
|
-
effects.enter("tableDelimiterRow");
|
|
3323
|
-
seen = false;
|
|
3324
|
-
if (markdownSpace(code2)) {
|
|
3325
|
-
return factorySpace(effects, headDelimiterBefore, "linePrefix", self.parser.constructs.disable.null.includes("codeIndented") ? void 0 : 4)(code2);
|
|
3326
|
-
}
|
|
3327
|
-
return headDelimiterBefore(code2);
|
|
3328
|
-
}
|
|
3329
|
-
function headDelimiterBefore(code2) {
|
|
3330
|
-
if (code2 === 45 || code2 === 58) {
|
|
3331
|
-
return headDelimiterValueBefore(code2);
|
|
3332
|
-
}
|
|
3333
|
-
if (code2 === 124) {
|
|
3334
|
-
seen = true;
|
|
3335
|
-
effects.enter("tableCellDivider");
|
|
3336
|
-
effects.consume(code2);
|
|
3337
|
-
effects.exit("tableCellDivider");
|
|
3338
|
-
return headDelimiterCellBefore;
|
|
3339
|
-
}
|
|
3340
|
-
return headDelimiterNok(code2);
|
|
3341
|
-
}
|
|
3342
|
-
function headDelimiterCellBefore(code2) {
|
|
3343
|
-
if (markdownSpace(code2)) {
|
|
3344
|
-
return factorySpace(effects, headDelimiterValueBefore, "whitespace")(code2);
|
|
3345
|
-
}
|
|
3346
|
-
return headDelimiterValueBefore(code2);
|
|
3347
|
-
}
|
|
3348
|
-
function headDelimiterValueBefore(code2) {
|
|
3349
|
-
if (code2 === 58) {
|
|
3350
|
-
sizeB += 1;
|
|
3351
|
-
seen = true;
|
|
3352
|
-
effects.enter("tableDelimiterMarker");
|
|
3353
|
-
effects.consume(code2);
|
|
3354
|
-
effects.exit("tableDelimiterMarker");
|
|
3355
|
-
return headDelimiterLeftAlignmentAfter;
|
|
3356
|
-
}
|
|
3357
|
-
if (code2 === 45) {
|
|
3358
|
-
sizeB += 1;
|
|
3359
|
-
return headDelimiterLeftAlignmentAfter(code2);
|
|
3360
|
-
}
|
|
3361
|
-
if (code2 === null || markdownLineEnding(code2)) {
|
|
3362
|
-
return headDelimiterCellAfter(code2);
|
|
3363
|
-
}
|
|
3364
|
-
return headDelimiterNok(code2);
|
|
3365
|
-
}
|
|
3366
|
-
function headDelimiterLeftAlignmentAfter(code2) {
|
|
3367
|
-
if (code2 === 45) {
|
|
3368
|
-
effects.enter("tableDelimiterFiller");
|
|
3369
|
-
return headDelimiterFiller(code2);
|
|
3370
|
-
}
|
|
3371
|
-
return headDelimiterNok(code2);
|
|
3372
|
-
}
|
|
3373
|
-
function headDelimiterFiller(code2) {
|
|
3374
|
-
if (code2 === 45) {
|
|
3375
|
-
effects.consume(code2);
|
|
3376
|
-
return headDelimiterFiller;
|
|
3377
|
-
}
|
|
3378
|
-
if (code2 === 58) {
|
|
3379
|
-
seen = true;
|
|
3380
|
-
effects.exit("tableDelimiterFiller");
|
|
3381
|
-
effects.enter("tableDelimiterMarker");
|
|
3382
|
-
effects.consume(code2);
|
|
3383
|
-
effects.exit("tableDelimiterMarker");
|
|
3384
|
-
return headDelimiterRightAlignmentAfter;
|
|
3385
|
-
}
|
|
3386
|
-
effects.exit("tableDelimiterFiller");
|
|
3387
|
-
return headDelimiterRightAlignmentAfter(code2);
|
|
3388
|
-
}
|
|
3389
|
-
function headDelimiterRightAlignmentAfter(code2) {
|
|
3390
|
-
if (markdownSpace(code2)) {
|
|
3391
|
-
return factorySpace(effects, headDelimiterCellAfter, "whitespace")(code2);
|
|
3392
|
-
}
|
|
3393
|
-
return headDelimiterCellAfter(code2);
|
|
3394
|
-
}
|
|
3395
|
-
function headDelimiterCellAfter(code2) {
|
|
3396
|
-
if (code2 === 124) {
|
|
3397
|
-
return headDelimiterBefore(code2);
|
|
3398
|
-
}
|
|
3399
|
-
if (code2 === null || markdownLineEnding(code2)) {
|
|
3400
|
-
if (!seen || size !== sizeB) {
|
|
3401
|
-
return headDelimiterNok(code2);
|
|
3402
|
-
}
|
|
3403
|
-
effects.exit("tableDelimiterRow");
|
|
3404
|
-
effects.exit("tableHead");
|
|
3405
|
-
return ok2(code2);
|
|
3406
|
-
}
|
|
3407
|
-
return headDelimiterNok(code2);
|
|
3408
|
-
}
|
|
3409
|
-
function headDelimiterNok(code2) {
|
|
3410
|
-
return nok(code2);
|
|
3411
|
-
}
|
|
3412
|
-
function bodyRowStart(code2) {
|
|
3413
|
-
effects.enter("tableRow");
|
|
3414
|
-
return bodyRowBreak(code2);
|
|
3415
|
-
}
|
|
3416
|
-
function bodyRowBreak(code2) {
|
|
3417
|
-
if (code2 === 124) {
|
|
3418
|
-
effects.enter("tableCellDivider");
|
|
3419
|
-
effects.consume(code2);
|
|
3420
|
-
effects.exit("tableCellDivider");
|
|
3421
|
-
return bodyRowBreak;
|
|
3422
|
-
}
|
|
3423
|
-
if (code2 === null || markdownLineEnding(code2)) {
|
|
3424
|
-
effects.exit("tableRow");
|
|
3425
|
-
return ok2(code2);
|
|
3426
|
-
}
|
|
3427
|
-
if (markdownSpace(code2)) {
|
|
3428
|
-
return factorySpace(effects, bodyRowBreak, "whitespace")(code2);
|
|
3429
|
-
}
|
|
3430
|
-
effects.enter("data");
|
|
3431
|
-
return bodyRowData(code2);
|
|
3432
|
-
}
|
|
3433
|
-
function bodyRowData(code2) {
|
|
3434
|
-
if (code2 === null || code2 === 124 || markdownLineEndingOrSpace(code2)) {
|
|
3435
|
-
effects.exit("data");
|
|
3436
|
-
return bodyRowBreak(code2);
|
|
3437
|
-
}
|
|
3438
|
-
effects.consume(code2);
|
|
3439
|
-
return code2 === 92 ? bodyRowEscape : bodyRowData;
|
|
3440
|
-
}
|
|
3441
|
-
function bodyRowEscape(code2) {
|
|
3442
|
-
if (code2 === 92 || code2 === 124) {
|
|
3443
|
-
effects.consume(code2);
|
|
3444
|
-
return bodyRowData;
|
|
3445
|
-
}
|
|
3446
|
-
return bodyRowData(code2);
|
|
3447
|
-
}
|
|
3448
|
-
}
|
|
3449
|
-
function resolveTable(events, context) {
|
|
3450
|
-
let index = -1;
|
|
3451
|
-
let inFirstCellAwaitingPipe = true;
|
|
3452
|
-
let rowKind = 0;
|
|
3453
|
-
let lastCell = [0, 0, 0, 0];
|
|
3454
|
-
let cell = [0, 0, 0, 0];
|
|
3455
|
-
let afterHeadAwaitingFirstBodyRow = false;
|
|
3456
|
-
let lastTableEnd = 0;
|
|
3457
|
-
let currentTable;
|
|
3458
|
-
let currentBody;
|
|
3459
|
-
let currentCell;
|
|
3460
|
-
const map2 = new EditMap();
|
|
3461
|
-
while (++index < events.length) {
|
|
3462
|
-
const event = events[index];
|
|
3463
|
-
const token = event[1];
|
|
3464
|
-
if (event[0] === "enter") {
|
|
3465
|
-
if (token.type === "tableHead") {
|
|
3466
|
-
afterHeadAwaitingFirstBodyRow = false;
|
|
3467
|
-
if (lastTableEnd !== 0) {
|
|
3468
|
-
flushTableEnd(map2, context, lastTableEnd, currentTable, currentBody);
|
|
3469
|
-
currentBody = void 0;
|
|
3470
|
-
lastTableEnd = 0;
|
|
3471
|
-
}
|
|
3472
|
-
currentTable = {
|
|
3473
|
-
type: "table",
|
|
3474
|
-
start: Object.assign({}, token.start),
|
|
3475
|
-
// Note: correct end is set later.
|
|
3476
|
-
end: Object.assign({}, token.end)
|
|
3477
|
-
};
|
|
3478
|
-
map2.add(index, 0, [["enter", currentTable, context]]);
|
|
3479
|
-
} else if (token.type === "tableRow" || token.type === "tableDelimiterRow") {
|
|
3480
|
-
inFirstCellAwaitingPipe = true;
|
|
3481
|
-
currentCell = void 0;
|
|
3482
|
-
lastCell = [0, 0, 0, 0];
|
|
3483
|
-
cell = [0, index + 1, 0, 0];
|
|
3484
|
-
if (afterHeadAwaitingFirstBodyRow) {
|
|
3485
|
-
afterHeadAwaitingFirstBodyRow = false;
|
|
3486
|
-
currentBody = {
|
|
3487
|
-
type: "tableBody",
|
|
3488
|
-
start: Object.assign({}, token.start),
|
|
3489
|
-
// Note: correct end is set later.
|
|
3490
|
-
end: Object.assign({}, token.end)
|
|
3491
|
-
};
|
|
3492
|
-
map2.add(index, 0, [["enter", currentBody, context]]);
|
|
3493
|
-
}
|
|
3494
|
-
rowKind = token.type === "tableDelimiterRow" ? 2 : currentBody ? 3 : 1;
|
|
3495
|
-
} else if (rowKind && (token.type === "data" || token.type === "tableDelimiterMarker" || token.type === "tableDelimiterFiller")) {
|
|
3496
|
-
inFirstCellAwaitingPipe = false;
|
|
3497
|
-
if (cell[2] === 0) {
|
|
3498
|
-
if (lastCell[1] !== 0) {
|
|
3499
|
-
cell[0] = cell[1];
|
|
3500
|
-
currentCell = flushCell(map2, context, lastCell, rowKind, void 0, currentCell);
|
|
3501
|
-
lastCell = [0, 0, 0, 0];
|
|
3502
|
-
}
|
|
3503
|
-
cell[2] = index;
|
|
3504
|
-
}
|
|
3505
|
-
} else if (token.type === "tableCellDivider") {
|
|
3506
|
-
if (inFirstCellAwaitingPipe) {
|
|
3507
|
-
inFirstCellAwaitingPipe = false;
|
|
3508
|
-
} else {
|
|
3509
|
-
if (lastCell[1] !== 0) {
|
|
3510
|
-
cell[0] = cell[1];
|
|
3511
|
-
currentCell = flushCell(map2, context, lastCell, rowKind, void 0, currentCell);
|
|
3512
|
-
}
|
|
3513
|
-
lastCell = cell;
|
|
3514
|
-
cell = [lastCell[1], index, 0, 0];
|
|
3515
|
-
}
|
|
3516
|
-
}
|
|
3517
|
-
} else if (token.type === "tableHead") {
|
|
3518
|
-
afterHeadAwaitingFirstBodyRow = true;
|
|
3519
|
-
lastTableEnd = index;
|
|
3520
|
-
} else if (token.type === "tableRow" || token.type === "tableDelimiterRow") {
|
|
3521
|
-
lastTableEnd = index;
|
|
3522
|
-
if (lastCell[1] !== 0) {
|
|
3523
|
-
cell[0] = cell[1];
|
|
3524
|
-
currentCell = flushCell(map2, context, lastCell, rowKind, index, currentCell);
|
|
3525
|
-
} else if (cell[1] !== 0) {
|
|
3526
|
-
currentCell = flushCell(map2, context, cell, rowKind, index, currentCell);
|
|
3527
|
-
}
|
|
3528
|
-
rowKind = 0;
|
|
3529
|
-
} else if (rowKind && (token.type === "data" || token.type === "tableDelimiterMarker" || token.type === "tableDelimiterFiller")) {
|
|
3530
|
-
cell[3] = index;
|
|
3531
|
-
}
|
|
3532
|
-
}
|
|
3533
|
-
if (lastTableEnd !== 0) {
|
|
3534
|
-
flushTableEnd(map2, context, lastTableEnd, currentTable, currentBody);
|
|
3535
|
-
}
|
|
3536
|
-
map2.consume(context.events);
|
|
3537
|
-
index = -1;
|
|
3538
|
-
while (++index < context.events.length) {
|
|
3539
|
-
const event = context.events[index];
|
|
3540
|
-
if (event[0] === "enter" && event[1].type === "table") {
|
|
3541
|
-
event[1]._align = gfmTableAlign(context.events, index);
|
|
3542
|
-
}
|
|
3543
|
-
}
|
|
3544
|
-
return events;
|
|
3545
|
-
}
|
|
3546
|
-
function flushCell(map2, context, range, rowKind, rowEnd, previousCell) {
|
|
3547
|
-
const groupName = rowKind === 1 ? "tableHeader" : rowKind === 2 ? "tableDelimiter" : "tableData";
|
|
3548
|
-
const valueName = "tableContent";
|
|
3549
|
-
if (range[0] !== 0) {
|
|
3550
|
-
previousCell.end = Object.assign({}, getPoint(context.events, range[0]));
|
|
3551
|
-
map2.add(range[0], 0, [["exit", previousCell, context]]);
|
|
3552
|
-
}
|
|
3553
|
-
const now = getPoint(context.events, range[1]);
|
|
3554
|
-
previousCell = {
|
|
3555
|
-
type: groupName,
|
|
3556
|
-
start: Object.assign({}, now),
|
|
3557
|
-
// Note: correct end is set later.
|
|
3558
|
-
end: Object.assign({}, now)
|
|
3559
|
-
};
|
|
3560
|
-
map2.add(range[1], 0, [["enter", previousCell, context]]);
|
|
3561
|
-
if (range[2] !== 0) {
|
|
3562
|
-
const relatedStart = getPoint(context.events, range[2]);
|
|
3563
|
-
const relatedEnd = getPoint(context.events, range[3]);
|
|
3564
|
-
const valueToken = {
|
|
3565
|
-
type: valueName,
|
|
3566
|
-
start: Object.assign({}, relatedStart),
|
|
3567
|
-
end: Object.assign({}, relatedEnd)
|
|
3568
|
-
};
|
|
3569
|
-
map2.add(range[2], 0, [["enter", valueToken, context]]);
|
|
3570
|
-
if (rowKind !== 2) {
|
|
3571
|
-
const start = context.events[range[2]];
|
|
3572
|
-
const end = context.events[range[3]];
|
|
3573
|
-
start[1].end = Object.assign({}, end[1].end);
|
|
3574
|
-
start[1].type = "chunkText";
|
|
3575
|
-
start[1].contentType = "text";
|
|
3576
|
-
if (range[3] > range[2] + 1) {
|
|
3577
|
-
const a = range[2] + 1;
|
|
3578
|
-
const b = range[3] - range[2] - 1;
|
|
3579
|
-
map2.add(a, b, []);
|
|
3580
|
-
}
|
|
3581
|
-
}
|
|
3582
|
-
map2.add(range[3] + 1, 0, [["exit", valueToken, context]]);
|
|
3583
|
-
}
|
|
3584
|
-
if (rowEnd !== void 0) {
|
|
3585
|
-
previousCell.end = Object.assign({}, getPoint(context.events, rowEnd));
|
|
3586
|
-
map2.add(rowEnd, 0, [["exit", previousCell, context]]);
|
|
3587
|
-
previousCell = void 0;
|
|
3588
|
-
}
|
|
3589
|
-
return previousCell;
|
|
3590
|
-
}
|
|
3591
|
-
function flushTableEnd(map2, context, index, table, tableBody) {
|
|
3592
|
-
const exits = [];
|
|
3593
|
-
const related = getPoint(context.events, index);
|
|
3594
|
-
if (tableBody) {
|
|
3595
|
-
tableBody.end = Object.assign({}, related);
|
|
3596
|
-
exits.push(["exit", tableBody, context]);
|
|
3597
|
-
}
|
|
3598
|
-
table.end = Object.assign({}, related);
|
|
3599
|
-
exits.push(["exit", table, context]);
|
|
3600
|
-
map2.add(index + 1, 0, exits);
|
|
3601
|
-
}
|
|
3602
|
-
function getPoint(events, index) {
|
|
3603
|
-
const event = events[index];
|
|
3604
|
-
const side = event[0] === "enter" ? "start" : "end";
|
|
3605
|
-
return event[1][side];
|
|
3606
|
-
}
|
|
3607
|
-
const tasklistCheck = {
|
|
3608
|
-
name: "tasklistCheck",
|
|
3609
|
-
tokenize: tokenizeTasklistCheck
|
|
3610
|
-
};
|
|
3611
|
-
function gfmTaskListItem() {
|
|
3612
|
-
return {
|
|
3613
|
-
text: {
|
|
3614
|
-
[91]: tasklistCheck
|
|
3615
|
-
}
|
|
3616
|
-
};
|
|
3617
|
-
}
|
|
3618
|
-
function tokenizeTasklistCheck(effects, ok2, nok) {
|
|
3619
|
-
const self = this;
|
|
3620
|
-
return open;
|
|
3621
|
-
function open(code2) {
|
|
3622
|
-
if (
|
|
3623
|
-
// Exit if there’s stuff before.
|
|
3624
|
-
self.previous !== null || // Exit if not in the first content that is the first child of a list
|
|
3625
|
-
// item.
|
|
3626
|
-
!self._gfmTasklistFirstContentOfListItem
|
|
3627
|
-
) {
|
|
3628
|
-
return nok(code2);
|
|
3629
|
-
}
|
|
3630
|
-
effects.enter("taskListCheck");
|
|
3631
|
-
effects.enter("taskListCheckMarker");
|
|
3632
|
-
effects.consume(code2);
|
|
3633
|
-
effects.exit("taskListCheckMarker");
|
|
3634
|
-
return inside;
|
|
3635
|
-
}
|
|
3636
|
-
function inside(code2) {
|
|
3637
|
-
if (markdownLineEndingOrSpace(code2)) {
|
|
3638
|
-
effects.enter("taskListCheckValueUnchecked");
|
|
3639
|
-
effects.consume(code2);
|
|
3640
|
-
effects.exit("taskListCheckValueUnchecked");
|
|
3641
|
-
return close;
|
|
3642
|
-
}
|
|
3643
|
-
if (code2 === 88 || code2 === 120) {
|
|
3644
|
-
effects.enter("taskListCheckValueChecked");
|
|
3645
|
-
effects.consume(code2);
|
|
3646
|
-
effects.exit("taskListCheckValueChecked");
|
|
3647
|
-
return close;
|
|
3648
|
-
}
|
|
3649
|
-
return nok(code2);
|
|
3650
|
-
}
|
|
3651
|
-
function close(code2) {
|
|
3652
|
-
if (code2 === 93) {
|
|
3653
|
-
effects.enter("taskListCheckMarker");
|
|
3654
|
-
effects.consume(code2);
|
|
3655
|
-
effects.exit("taskListCheckMarker");
|
|
3656
|
-
effects.exit("taskListCheck");
|
|
3657
|
-
return after;
|
|
3658
|
-
}
|
|
3659
|
-
return nok(code2);
|
|
3660
|
-
}
|
|
3661
|
-
function after(code2) {
|
|
3662
|
-
if (markdownLineEnding(code2)) {
|
|
3663
|
-
return ok2(code2);
|
|
3664
|
-
}
|
|
3665
|
-
if (markdownSpace(code2)) {
|
|
3666
|
-
return effects.check({
|
|
3667
|
-
tokenize: spaceThenNonSpace
|
|
3668
|
-
}, ok2, nok)(code2);
|
|
3669
|
-
}
|
|
3670
|
-
return nok(code2);
|
|
3671
|
-
}
|
|
3672
|
-
}
|
|
3673
|
-
function spaceThenNonSpace(effects, ok2, nok) {
|
|
3674
|
-
return factorySpace(effects, after, "whitespace");
|
|
3675
|
-
function after(code2) {
|
|
3676
|
-
return code2 === null ? nok(code2) : ok2(code2);
|
|
3677
|
-
}
|
|
3678
|
-
}
|
|
3679
|
-
function gfm(options) {
|
|
3680
|
-
return combineExtensions([
|
|
3681
|
-
gfmAutolinkLiteral(),
|
|
3682
|
-
gfmFootnote(),
|
|
3683
|
-
gfmStrikethrough(options),
|
|
3684
|
-
gfmTable(),
|
|
3685
|
-
gfmTaskListItem()
|
|
3686
|
-
]);
|
|
3687
|
-
}
|
|
3688
|
-
const emptyOptions = {};
|
|
3689
|
-
function remarkGfm(options) {
|
|
3690
|
-
const self = (
|
|
3691
|
-
/** @type {Processor<Root>} */
|
|
3692
|
-
this
|
|
3693
|
-
);
|
|
3694
|
-
const settings = options || emptyOptions;
|
|
3695
|
-
const data = self.data();
|
|
3696
|
-
const micromarkExtensions = data.micromarkExtensions || (data.micromarkExtensions = []);
|
|
3697
|
-
const fromMarkdownExtensions = data.fromMarkdownExtensions || (data.fromMarkdownExtensions = []);
|
|
3698
|
-
const toMarkdownExtensions = data.toMarkdownExtensions || (data.toMarkdownExtensions = []);
|
|
3699
|
-
micromarkExtensions.push(gfm(settings));
|
|
3700
|
-
fromMarkdownExtensions.push(gfmFromMarkdown());
|
|
3701
|
-
toMarkdownExtensions.push(gfmToMarkdown(settings));
|
|
3702
|
-
}
|
|
3703
|
-
function createOlympusAssetUrl({
|
|
3704
|
-
appUrl,
|
|
3705
|
-
backendUrl,
|
|
3706
|
-
assetIds
|
|
3707
|
-
}) {
|
|
3708
|
-
const resolvedAppUrl = (appUrl == null ? void 0 : appUrl.trim()) || (backendUrl ? scopeRegistry.deriveAthenaAppUrl({ backendUrl }) : null);
|
|
3709
|
-
if (!resolvedAppUrl) return null;
|
|
3710
|
-
const url = scopeRegistry.createAthenaSpacesUrl({
|
|
3711
|
-
appUrl: resolvedAppUrl,
|
|
3712
|
-
assetIds
|
|
3713
|
-
});
|
|
3714
|
-
return new URL(url).toString();
|
|
3715
|
-
}
|
|
3716
|
-
function authorizationHeaders(auth) {
|
|
3717
|
-
if (auth.accessToken) {
|
|
3718
|
-
return { Authorization: `Bearer ${auth.accessToken}` };
|
|
3719
|
-
}
|
|
3720
|
-
if (auth.apiKey) return { "X-API-KEY": auth.apiKey };
|
|
3721
|
-
throw new Error("MentionAuthCtx needs either an accessToken or an apiKey");
|
|
3722
|
-
}
|
|
3723
|
-
const MentionAuthCtx = React.createContext(null);
|
|
3724
|
-
function useMentionAuth() {
|
|
3725
|
-
const ctx = React.useContext(MentionAuthCtx);
|
|
3726
|
-
if (!ctx) throw new Error("MentionAuthCtx not provided");
|
|
3727
|
-
return ctx;
|
|
3728
|
-
}
|
|
3729
|
-
async function fetchGraphQL(auth, query, variables = {}) {
|
|
3730
|
-
var _a;
|
|
3731
|
-
const url = `${auth.backendUrl.replace(/\/+$/, "")}/graphql`;
|
|
3732
|
-
const response = await fetch(url, {
|
|
3733
|
-
method: "POST",
|
|
3734
|
-
headers: {
|
|
3735
|
-
"Content-Type": "application/json",
|
|
3736
|
-
...authorizationHeaders(auth)
|
|
3737
|
-
},
|
|
3738
|
-
body: JSON.stringify({ query, variables })
|
|
3739
|
-
});
|
|
3740
|
-
if (!response.ok) {
|
|
3741
|
-
throw new Error(`GraphQL HTTP ${response.status}: ${response.statusText}`);
|
|
3742
|
-
}
|
|
3743
|
-
const result = await response.json();
|
|
3744
|
-
if ((_a = result.errors) == null ? void 0 : _a.length) {
|
|
3745
|
-
throw new Error(`GraphQL error: ${result.errors[0].message}`);
|
|
3746
|
-
}
|
|
3747
|
-
return result.data;
|
|
3748
|
-
}
|
|
3749
|
-
const MENTION_ASSET_FIELDS = `
|
|
3750
|
-
id
|
|
3751
|
-
title
|
|
3752
|
-
athenaOriginalType
|
|
3753
|
-
athenaConvertedType
|
|
3754
|
-
parentFolderId
|
|
3755
|
-
updatedAt
|
|
3756
|
-
isFavorited
|
|
3757
|
-
isArchived
|
|
3758
|
-
isHidden
|
|
3759
|
-
`;
|
|
3760
|
-
const SIMPLE_SEARCH_QUERY = `
|
|
3761
|
-
query SimpleSearch($input: SimpleSearchRequestInput!) {
|
|
3762
|
-
simpleSearch(input: $input) {
|
|
3763
|
-
assets {
|
|
3764
|
-
${MENTION_ASSET_FIELDS}
|
|
3765
|
-
}
|
|
3766
|
-
totalCount
|
|
3767
|
-
}
|
|
3768
|
-
}
|
|
3769
|
-
`;
|
|
3770
|
-
const PAGINATED_ASSETS_QUERY = `
|
|
3771
|
-
query GetPaginatedAssetsForWorkspace(
|
|
3772
|
-
$limit: Int!
|
|
3773
|
-
$offset: Int!
|
|
3774
|
-
$parentFolderId: String
|
|
3775
|
-
$filterTypes: [String!]
|
|
3776
|
-
$filterColumns: ColumnFilter
|
|
3777
|
-
) {
|
|
3778
|
-
getPaginatedAssetsForWorkspace(
|
|
3779
|
-
limit: $limit
|
|
3780
|
-
offset: $offset
|
|
3781
|
-
parentFolderId: $parentFolderId
|
|
3782
|
-
filterTypes: $filterTypes
|
|
3783
|
-
filterColumns: $filterColumns
|
|
3784
|
-
) {
|
|
3785
|
-
${MENTION_ASSET_FIELDS}
|
|
3786
|
-
}
|
|
3787
|
-
}
|
|
3788
|
-
`;
|
|
3789
|
-
const WORKSPACE_MEMBERS_QUERY = `
|
|
3790
|
-
query GetUsersInWorkspace($workspaceId: String!) {
|
|
3791
|
-
getUsersInWorkspace(workspaceId: $workspaceId) {
|
|
3792
|
-
id
|
|
3793
|
-
email
|
|
3794
|
-
firstName
|
|
3795
|
-
lastName
|
|
3796
|
-
isAdmin
|
|
3797
|
-
avatarUrl
|
|
3798
|
-
}
|
|
3799
|
-
}
|
|
3800
|
-
`;
|
|
3801
|
-
let iconBasePath = null;
|
|
3802
|
-
function configureAssetIconBasePath({
|
|
3803
|
-
basePath
|
|
3804
|
-
}) {
|
|
3805
|
-
iconBasePath = basePath ? basePath.replace(/\/*$/, "/") : basePath;
|
|
3806
|
-
}
|
|
3807
|
-
const ASSET_TYPE_ICON_FILE = {
|
|
3808
|
-
// Documents
|
|
3809
|
-
folder: "ic-folder",
|
|
3810
|
-
txt: "ic-txt",
|
|
3811
|
-
document: "ic-word",
|
|
3812
|
-
word_document: "ic-word",
|
|
3813
|
-
markdown: "ic-md",
|
|
3814
|
-
pdf: "ic-pdf",
|
|
3815
|
-
html: "ic-html",
|
|
3816
|
-
web_page: "ic-html",
|
|
3817
|
-
yaml: "ic-yaml",
|
|
3818
|
-
json: "ic-json",
|
|
3819
|
-
// Spreadsheets
|
|
3820
|
-
spreadsheet: "ic-excel",
|
|
3821
|
-
table: "ic-table",
|
|
3822
|
-
// Media
|
|
3823
|
-
image: "ic-img",
|
|
3824
|
-
audio: "ic-audio",
|
|
3825
|
-
video: "ic-video",
|
|
3826
|
-
voice_memo: "ic-audio",
|
|
3827
|
-
// Presentations
|
|
3828
|
-
presentation: "ic-power_point",
|
|
3829
|
-
office_presentation: "ic-power_point",
|
|
3830
|
-
powerpoint_deck: "ic-power_point",
|
|
3831
|
-
presentation_pptx_studio: "ic-power_point",
|
|
3832
|
-
presentation_onlyoffice: "ic-power_point",
|
|
3833
|
-
pptx: "ic-power_point",
|
|
3834
|
-
// Email & Calendar
|
|
3835
|
-
email: "ic-mail",
|
|
3836
|
-
email_message: "ic-mail",
|
|
3837
|
-
live_email_thread: "ic-mail",
|
|
3838
|
-
live_calendar_event: "ic-mail",
|
|
3839
|
-
// Code
|
|
3840
|
-
python: "ic-py",
|
|
3841
|
-
javascript: "ic-js",
|
|
3842
|
-
typescript: "ic-code",
|
|
3843
|
-
jsx: "ic-code",
|
|
3844
|
-
tsx: "ic-code",
|
|
3845
|
-
css: "ic-code",
|
|
3846
|
-
java: "ic-code",
|
|
3847
|
-
c: "ic-code",
|
|
3848
|
-
cpp: "ic-code",
|
|
3849
|
-
csharp: "ic-code",
|
|
3850
|
-
ruby: "ic-code",
|
|
3851
|
-
go: "ic-code",
|
|
3852
|
-
swift: "ic-code",
|
|
3853
|
-
php: "ic-code",
|
|
3854
|
-
rust: "ic-code",
|
|
3855
|
-
vue: "ic-code",
|
|
3856
|
-
wm_script: "ic-code",
|
|
3857
|
-
// Structured data
|
|
3858
|
-
database: "ic-snippet",
|
|
3859
|
-
schema: "ic-schema",
|
|
3860
|
-
catalog: "ic-db",
|
|
3861
|
-
drive: "ic-db",
|
|
3862
|
-
query_snippet: "ic-snippet",
|
|
3863
|
-
semantic_model: "ic-db",
|
|
3864
|
-
// Meetings & Calls
|
|
3865
|
-
meeting: "ic-meeting",
|
|
3866
|
-
video_session: "ic-meeting",
|
|
3867
|
-
phone_call: "ic-phonecall",
|
|
3868
|
-
// Sessions & Devices
|
|
3869
|
-
session: "ic-session",
|
|
3870
|
-
browse_session: "ic-html",
|
|
3871
|
-
virtual_machine: "ic-html",
|
|
3872
|
-
computer: "ic-computer",
|
|
3873
|
-
desktop_session: "ic-desktop_session",
|
|
3874
|
-
mobile_session: "ic-mobile_session",
|
|
3875
|
-
// Projects & Profiles
|
|
3876
|
-
project: "ic-project",
|
|
3877
|
-
browse_profile: "ic-profile",
|
|
3878
|
-
// Workflows & Automation
|
|
3879
|
-
aop: "ic-flow",
|
|
3880
|
-
playbook: "ic-flow",
|
|
3881
|
-
flow: "ic-flow",
|
|
3882
|
-
transform_project: "ic-flow",
|
|
3883
|
-
// Collections & Notebooks
|
|
3884
|
-
collection: "ic-collection",
|
|
3885
|
-
notebook: "ic-notebook",
|
|
3886
|
-
// UI & Apps
|
|
3887
|
-
user_interface: "ic-app",
|
|
3888
|
-
canvas: "ic-canvas",
|
|
3889
|
-
dashboard: "ic-dashboard",
|
|
3890
|
-
figure: "ic_figure",
|
|
3891
|
-
// People & Companies
|
|
3892
|
-
person: "ic-person",
|
|
3893
|
-
company: "ic-company",
|
|
3894
|
-
// Misc
|
|
3895
|
-
prompt: "ic-ai",
|
|
3896
|
-
task_item: "ic-task",
|
|
3897
|
-
spaces: "ic-spaces",
|
|
3898
|
-
secret: "ic-secret",
|
|
3899
|
-
photoshop: "ic-pts",
|
|
3900
|
-
illustrator: "ic-ai",
|
|
3901
|
-
zip: "ic-zip",
|
|
3902
|
-
sevenzip: "ic-zip",
|
|
3903
|
-
// Google Drive / SharePoint / Salesforce
|
|
3904
|
-
gdrive_folder: "ic-folder",
|
|
3905
|
-
gdrive_file: "ic-file",
|
|
3906
|
-
salesforce_record: "ic-db",
|
|
3907
|
-
salesforce_file: "ic-db"
|
|
3908
|
-
};
|
|
3909
|
-
const ASSET_TYPE_LUCIDE_FALLBACK = {
|
|
3910
|
-
folder: "folder",
|
|
3911
|
-
spreadsheet: "sheet",
|
|
3912
|
-
image: "image",
|
|
3913
|
-
video: "video",
|
|
3914
|
-
audio: "headphones",
|
|
3915
|
-
email: "mail",
|
|
3916
|
-
database: "database",
|
|
3917
|
-
project: "folder-kanban",
|
|
3918
|
-
meeting: "video",
|
|
3919
|
-
user_interface: "layout"
|
|
3920
|
-
};
|
|
3921
|
-
function assetTypeToThumb(assetType) {
|
|
3922
|
-
if (!iconBasePath) return void 0;
|
|
3923
|
-
const name = (assetType ? ASSET_TYPE_ICON_FILE[assetType.toLowerCase()] : void 0) ?? "ic-file";
|
|
3924
|
-
return `${iconBasePath}${name}.svg`;
|
|
3925
|
-
}
|
|
3926
|
-
function assetTypeToIcon(assetType) {
|
|
3927
|
-
if (!assetType) return "file";
|
|
3928
|
-
return ASSET_TYPE_LUCIDE_FALLBACK[assetType.toLowerCase()] ?? "file";
|
|
3929
|
-
}
|
|
3930
|
-
const SPACES_MENTION_PATH = /\/dashboard\/spaces\/?\?/;
|
|
3931
|
-
function isSpacesMentionUrl(url) {
|
|
3932
|
-
return SPACES_MENTION_PATH.test(url);
|
|
3933
|
-
}
|
|
3934
|
-
function getSpacesAssetType(url) {
|
|
3935
|
-
const assetType = url.searchParams.get("assetType") || url.searchParams.get("asset_type") || url.searchParams.get("type");
|
|
3936
|
-
return assetType === "sheet" ? "spreadsheet" : assetType;
|
|
3937
|
-
}
|
|
3938
|
-
const MentionLink = ({ href, children }) => {
|
|
3939
|
-
if (href && (href.startsWith("mention://") || isSpacesMentionUrl(href))) {
|
|
3940
|
-
const name = typeof children === "string" ? children.replace(/^@/, "") : Array.isArray(children) ? String(children[0] ?? "").replace(/^@/, "") : "";
|
|
3941
|
-
const parsed = parseMentionUrl(href);
|
|
3942
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
3943
|
-
MentionChip,
|
|
3944
|
-
{
|
|
3945
|
-
name: name || parsed.name,
|
|
3946
|
-
type: parsed.type,
|
|
3947
|
-
assetIds: parsed.assetIds,
|
|
3948
|
-
thumbnailUrl: parsed.thumbnailUrl,
|
|
3949
|
-
sourceHref: isSpacesMentionUrl(href) ? href : void 0
|
|
3950
|
-
}
|
|
3951
|
-
);
|
|
3952
|
-
}
|
|
3953
|
-
if (href == null ? void 0 : href.startsWith("chrome-extension://")) {
|
|
3954
|
-
return /* @__PURE__ */ jsxRuntime.jsx("span", { children });
|
|
3955
|
-
}
|
|
3956
|
-
return /* @__PURE__ */ jsxRuntime.jsx("a", { href, target: "_blank", rel: "noopener noreferrer", children });
|
|
3957
|
-
};
|
|
3958
|
-
const MentionChip = ({ name, type, assetIds, thumbnailUrl, sourceHref }) => {
|
|
3959
|
-
const auth = React.useContext(MentionAuthCtx);
|
|
3960
|
-
const assetRootHref = type === "asset" && (assetIds == null ? void 0 : assetIds.length) ? createOlympusAssetUrl({
|
|
3961
|
-
appUrl: auth == null ? void 0 : auth.appUrl,
|
|
3962
|
-
backendUrl: auth == null ? void 0 : auth.backendUrl,
|
|
3963
|
-
assetIds
|
|
3964
|
-
}) : null;
|
|
3965
|
-
const href = (() => {
|
|
3966
|
-
if (!assetRootHref || !sourceHref) return assetRootHref;
|
|
3967
|
-
try {
|
|
3968
|
-
const source = new URL(sourceHref, "https://app.athenaintel.com");
|
|
3969
|
-
const destination = new URL(assetRootHref);
|
|
3970
|
-
for (const [key, value] of source.searchParams) {
|
|
3971
|
-
destination.searchParams.set(key, value);
|
|
3972
|
-
}
|
|
3973
|
-
destination.searchParams.set("asset_ids", (assetIds == null ? void 0 : assetIds.join(",")) ?? "");
|
|
3974
|
-
return destination.toString();
|
|
3975
|
-
} catch {
|
|
3976
|
-
return assetRootHref;
|
|
3977
|
-
}
|
|
3978
|
-
})();
|
|
3979
|
-
const className = scopeRegistry.cn(
|
|
3980
|
-
"not-prose inline-flex max-w-[220px] items-center gap-1 whitespace-nowrap rounded-md border border-slate-300 bg-white px-1.5 py-px align-middle text-[0.85em] font-medium leading-[1.4] text-slate-600 no-underline",
|
|
3981
|
-
href && "cursor-pointer transition-colors hover:border-slate-400 hover:bg-slate-50 hover:text-slate-800 hover:no-underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-1"
|
|
3982
|
-
);
|
|
3983
|
-
const contents = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
3984
|
-
thumbnailUrl && /* @__PURE__ */ jsxRuntime.jsx(
|
|
3985
|
-
"img",
|
|
3986
|
-
{
|
|
3987
|
-
src: thumbnailUrl,
|
|
3988
|
-
alt: "",
|
|
3989
|
-
className: "size-3.5 shrink-0",
|
|
3990
|
-
draggable: false
|
|
3991
|
-
}
|
|
3992
|
-
),
|
|
3993
|
-
!thumbnailUrl && type === "webpage" && /* @__PURE__ */ jsxRuntime.jsx(Earth, { className: "size-3.5 shrink-0", "aria-hidden": "true" }),
|
|
3994
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "max-w-[180px] overflow-hidden text-ellipsis", children: name })
|
|
3995
|
-
] });
|
|
3996
|
-
if (href) {
|
|
3997
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
3998
|
-
"a",
|
|
3999
|
-
{
|
|
4000
|
-
href,
|
|
4001
|
-
target: "_blank",
|
|
4002
|
-
rel: "noopener noreferrer",
|
|
4003
|
-
className,
|
|
4004
|
-
"aria-label": `Open ${name} in Spaces`,
|
|
4005
|
-
title: `Open ${name} in Spaces`,
|
|
4006
|
-
children: contents
|
|
4007
|
-
}
|
|
4008
|
-
);
|
|
4009
|
-
}
|
|
4010
|
-
return /* @__PURE__ */ jsxRuntime.jsx("span", { className, children: contents });
|
|
4011
|
-
};
|
|
4012
|
-
function parseMentionUrl(url) {
|
|
4013
|
-
try {
|
|
4014
|
-
if (isSpacesMentionUrl(url)) {
|
|
4015
|
-
const parsed = new URL(url, "https://app.athenaintel.com");
|
|
4016
|
-
const assetIds = (parsed.searchParams.get("asset_ids") ?? "").split(",").map((id3) => id3.trim()).filter(Boolean);
|
|
4017
|
-
const id2 = assetIds[0] ?? "";
|
|
4018
|
-
const assetType = getSpacesAssetType(parsed);
|
|
4019
|
-
return {
|
|
4020
|
-
type: "asset",
|
|
4021
|
-
name: assetIds.length > 1 ? `${assetIds.length} assets` : "Asset",
|
|
4022
|
-
id: id2,
|
|
4023
|
-
assetIds,
|
|
4024
|
-
thumbnailUrl: assetTypeToThumb(assetType)
|
|
4025
|
-
};
|
|
4026
|
-
}
|
|
4027
|
-
const u = new URL(url);
|
|
4028
|
-
const type = u.hostname || u.pathname.replace(/^\/\//, "").split("?")[0];
|
|
4029
|
-
const isWebpage = type === "webpage";
|
|
4030
|
-
const id = isWebpage ? u.searchParams.get("tab_id") || "" : u.searchParams.get("id") || u.searchParams.get("name") || "";
|
|
4031
|
-
const name = isWebpage ? u.searchParams.get("title") || "This webpage" : u.searchParams.get("name") || id;
|
|
4032
|
-
let thumbnailUrl = u.searchParams.get("thumb") || void 0;
|
|
4033
|
-
if (!thumbnailUrl) {
|
|
4034
|
-
const assetType = u.searchParams.get("assetType");
|
|
4035
|
-
if (assetType) {
|
|
4036
|
-
thumbnailUrl = assetTypeToThumb(assetType);
|
|
4037
|
-
} else if (type === "asset" || type === "folder") {
|
|
4038
|
-
thumbnailUrl = assetTypeToThumb(type === "folder" ? "folder" : null);
|
|
4039
|
-
}
|
|
4040
|
-
}
|
|
4041
|
-
return {
|
|
4042
|
-
type,
|
|
4043
|
-
name,
|
|
4044
|
-
id,
|
|
4045
|
-
assetIds: type === "asset" && id ? [id] : void 0,
|
|
4046
|
-
thumbnailUrl
|
|
4047
|
-
};
|
|
4048
|
-
} catch {
|
|
4049
|
-
return { type: "unknown", name: "", id: "" };
|
|
4050
|
-
}
|
|
4051
|
-
}
|
|
4052
|
-
function htmlAttribute(attributes, name) {
|
|
4053
|
-
const escapedName = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
4054
|
-
const match = new RegExp(
|
|
4055
|
-
`(?:^|\\s)${escapedName}\\s*=\\s*(?:"([^"]*)"|'([^']*)'|([^\\s>]+))`,
|
|
4056
|
-
"i"
|
|
4057
|
-
).exec(attributes);
|
|
4058
|
-
return (match == null ? void 0 : match[1]) ?? (match == null ? void 0 : match[2]) ?? (match == null ? void 0 : match[3]) ?? null;
|
|
4059
|
-
}
|
|
4060
|
-
function decodeHtmlAttribute(value) {
|
|
4061
|
-
return value.replace(/&/gi, "&").replace(/"/gi, '"').replace(/'|'/gi, "'").replace(/</gi, "<").replace(/>/gi, ">");
|
|
4062
|
-
}
|
|
4063
|
-
function normalizeAthenaMentionHtml(text2) {
|
|
4064
|
-
return text2.replace(
|
|
4065
|
-
/<a\b([^>]*)>([\s\S]*?)<\/a>/gi,
|
|
4066
|
-
(original, attributes, rawLabel) => {
|
|
4067
|
-
const className = htmlAttribute(attributes, "class") ?? "";
|
|
4068
|
-
const type = htmlAttribute(attributes, "data-type") ?? "";
|
|
4069
|
-
if (!className.split(/\s+/).includes("mention") || type !== "url") {
|
|
4070
|
-
return original;
|
|
4071
|
-
}
|
|
4072
|
-
const rawUrl = htmlAttribute(attributes, "data-url") ?? htmlAttribute(attributes, "href");
|
|
4073
|
-
if (!rawUrl) return original;
|
|
4074
|
-
const url = decodeHtmlAttribute(rawUrl);
|
|
4075
|
-
let normalizedUrl;
|
|
4076
|
-
try {
|
|
4077
|
-
const parsed = new URL(url);
|
|
4078
|
-
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
4079
|
-
return original;
|
|
4080
|
-
}
|
|
4081
|
-
normalizedUrl = parsed.toString();
|
|
4082
|
-
} catch {
|
|
4083
|
-
return original;
|
|
4084
|
-
}
|
|
4085
|
-
const label = decodeHtmlAttribute(rawLabel.replace(/<[^>]*>/g, "")).trim().replace(/([\\[\]])/g, "\\$1");
|
|
4086
|
-
return label ? `[${label}](<${normalizedUrl}>)` : original;
|
|
4087
|
-
}
|
|
4088
|
-
);
|
|
4089
|
-
}
|
|
4090
|
-
const MENTION_RE = /\[@([^\]]*)\]\(((?:mention:\/\/|(?:https?:\/\/[^)\s]+)?\/dashboard\/spaces\/?\?)[^)]+)\)/g;
|
|
4091
|
-
function parseMentionsInText(text2) {
|
|
4092
|
-
const parts = [];
|
|
4093
|
-
let lastIndex = 0;
|
|
4094
|
-
let match;
|
|
4095
|
-
MENTION_RE.lastIndex = 0;
|
|
4096
|
-
while ((match = MENTION_RE.exec(text2)) !== null) {
|
|
4097
|
-
if (match.index > lastIndex) {
|
|
4098
|
-
parts.push(text2.slice(lastIndex, match.index));
|
|
4099
|
-
}
|
|
4100
|
-
const name = match[1];
|
|
4101
|
-
const url = match[2];
|
|
4102
|
-
const parsed = parseMentionUrl(url);
|
|
4103
|
-
parts.push(
|
|
4104
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4105
|
-
MentionChip,
|
|
4106
|
-
{
|
|
4107
|
-
name: name || parsed.name,
|
|
4108
|
-
type: parsed.type,
|
|
4109
|
-
assetIds: parsed.assetIds,
|
|
4110
|
-
thumbnailUrl: parsed.thumbnailUrl,
|
|
4111
|
-
sourceHref: isSpacesMentionUrl(url) ? url : void 0
|
|
4112
|
-
},
|
|
4113
|
-
`mention-${match.index}`
|
|
4114
|
-
)
|
|
4115
|
-
);
|
|
4116
|
-
lastIndex = match.index + match[0].length;
|
|
4117
|
-
}
|
|
4118
|
-
if (lastIndex < text2.length) {
|
|
4119
|
-
parts.push(text2.slice(lastIndex));
|
|
4120
|
-
}
|
|
4121
|
-
return parts.length > 0 ? parts : [text2];
|
|
4122
|
-
}
|
|
4123
|
-
function hasVisibleContent(content) {
|
|
4124
|
-
return content.some(
|
|
4125
|
-
(part) => part.type === "tool-call" || part.type === "text" && part.text.trim().length > 0 || part.type === "reasoning" && part.text.trim().length > 0
|
|
4126
|
-
);
|
|
4127
|
-
}
|
|
4128
|
-
const TextShimmerLoader = ({
|
|
4129
|
-
text: text2 = "Thinking...",
|
|
4130
|
-
className
|
|
4131
|
-
}) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
4132
|
-
"span",
|
|
4133
|
-
{
|
|
4134
|
-
className: scopeRegistry.cn(
|
|
4135
|
-
"inline-block w-min animate-shimmer-ltr bg-gradient-to-r from-gray-500 via-gray-300 to-gray-500 bg-[200%_auto] bg-clip-text !text-transparent",
|
|
4136
|
-
className
|
|
4137
|
-
),
|
|
4138
|
-
children: text2
|
|
4139
|
-
}
|
|
4140
|
-
);
|
|
4141
|
-
const ThreadRunningIndicator = ({
|
|
4142
|
-
text: text2 = "Thinking..."
|
|
4143
|
-
}) => {
|
|
4144
|
-
const isWorking = react.useAuiState((state) => {
|
|
4145
|
-
const thread = state.optional.thread;
|
|
4146
|
-
if (!(thread == null ? void 0 : thread.isRunning)) return false;
|
|
4147
|
-
const last = thread.messages.at(-1);
|
|
4148
|
-
if (!last || last.role === "user") return true;
|
|
4149
|
-
if (last.role !== "assistant") return false;
|
|
4150
|
-
return !hasVisibleContent(last.content);
|
|
4151
|
-
});
|
|
4152
|
-
if (!isWorking) return null;
|
|
4153
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
4154
|
-
"div",
|
|
4155
|
-
{
|
|
4156
|
-
role: "status",
|
|
4157
|
-
"aria-label": "Athena is responding",
|
|
4158
|
-
className: "px-1 pb-2 pt-1",
|
|
4159
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(TextShimmerLoader, { text: text2, className: "text-xs" })
|
|
4160
|
-
}
|
|
4161
|
-
);
|
|
4162
|
-
};
|
|
4163
|
-
function IconButton({
|
|
4164
|
-
children,
|
|
4165
|
-
tooltip,
|
|
4166
|
-
className,
|
|
4167
|
-
...props
|
|
4168
|
-
}) {
|
|
4169
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
4170
|
-
"button",
|
|
4171
|
-
{
|
|
4172
|
-
type: "button",
|
|
4173
|
-
title: tooltip,
|
|
4174
|
-
"aria-label": tooltip,
|
|
4175
|
-
className: scopeRegistry.cn(
|
|
4176
|
-
"inline-flex size-9 items-center justify-center rounded-lg text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",
|
|
4177
|
-
className
|
|
4178
|
-
),
|
|
4179
|
-
...props,
|
|
4180
|
-
children
|
|
4181
|
-
}
|
|
4182
|
-
);
|
|
4183
|
-
}
|
|
4184
|
-
function SmallIconButton({
|
|
4185
|
-
children,
|
|
4186
|
-
tooltip,
|
|
4187
|
-
className,
|
|
4188
|
-
...props
|
|
4189
|
-
}) {
|
|
4190
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
4191
|
-
"button",
|
|
4192
|
-
{
|
|
4193
|
-
type: "button",
|
|
4194
|
-
title: tooltip,
|
|
4195
|
-
className: scopeRegistry.cn(
|
|
4196
|
-
"inline-flex size-6 items-center justify-center rounded text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground",
|
|
4197
|
-
className
|
|
4198
|
-
),
|
|
4199
|
-
...props,
|
|
4200
|
-
children
|
|
4201
|
-
}
|
|
4202
|
-
);
|
|
4203
|
-
}
|
|
4204
|
-
const BranchPicker = () => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
4205
|
-
react.BranchPickerPrimitive.Root,
|
|
4206
|
-
{
|
|
4207
|
-
hideWhenSingleBranch: true,
|
|
4208
|
-
className: "inline-flex items-center gap-0.5 text-xs text-muted-foreground",
|
|
4209
|
-
"data-testid": "chat-branch-picker",
|
|
4210
|
-
children: [
|
|
4211
|
-
/* @__PURE__ */ jsxRuntime.jsx(react.BranchPickerPrimitive.Previous, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
4212
|
-
SmallIconButton,
|
|
4213
|
-
{
|
|
4214
|
-
tooltip: "Previous branch",
|
|
4215
|
-
"data-testid": "chat-branch-previous",
|
|
4216
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(ChevronLeft, { className: "size-3" })
|
|
4217
|
-
}
|
|
4218
|
-
) }),
|
|
4219
|
-
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "font-medium", "data-testid": "chat-branch-count", children: [
|
|
4220
|
-
/* @__PURE__ */ jsxRuntime.jsx(react.BranchPickerPrimitive.Number, {}),
|
|
4221
|
-
" / ",
|
|
4222
|
-
/* @__PURE__ */ jsxRuntime.jsx(react.BranchPickerPrimitive.Count, {})
|
|
4223
|
-
] }),
|
|
4224
|
-
/* @__PURE__ */ jsxRuntime.jsx(react.BranchPickerPrimitive.Next, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(SmallIconButton, { tooltip: "Next branch", "data-testid": "chat-branch-next", children: /* @__PURE__ */ jsxRuntime.jsx(scopeRegistry.ChevronRight, { className: "size-3" }) }) })
|
|
4225
|
-
]
|
|
4226
|
-
}
|
|
4227
|
-
);
|
|
4228
|
-
const CopyActionButton = () => /* @__PURE__ */ jsxRuntime.jsx(react.ActionBarPrimitive.Copy, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsxs(SmallIconButton, { tooltip: "Copy", children: [
|
|
4229
|
-
/* @__PURE__ */ jsxRuntime.jsx(react.AuiIf, { condition: (state) => state.message.isCopied, children: /* @__PURE__ */ jsxRuntime.jsx(scopeRegistry.Check, { className: "size-3" }) }),
|
|
4230
|
-
/* @__PURE__ */ jsxRuntime.jsx(react.AuiIf, { condition: (state) => !state.message.isCopied, children: /* @__PURE__ */ jsxRuntime.jsx(scopeRegistry.Copy, { className: "size-3" }) })
|
|
4231
|
-
] }) });
|
|
4232
|
-
function CodeBlock({ language, code: code2 }) {
|
|
4233
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "not-prose my-2 overflow-hidden rounded-lg border border-border bg-muted/30", children: [
|
|
4234
|
-
language && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "border-b border-border bg-muted/50 px-3 py-1 text-[10px] font-medium text-muted-foreground", children: language }),
|
|
4235
|
-
/* @__PURE__ */ jsxRuntime.jsx("pre", { className: "overflow-x-auto p-3", children: /* @__PURE__ */ jsxRuntime.jsx("code", { className: "font-mono text-xs leading-relaxed text-foreground", children: code2 }) })
|
|
4236
|
-
] });
|
|
4237
|
-
}
|
|
4238
|
-
const MARKDOWN_CLASS = "aui-md prose prose-sm max-w-none text-foreground prose-p:my-1.5 prose-p:leading-relaxed prose-headings:mt-3 prose-headings:mb-1.5 prose-headings:font-semibold prose-h1:text-sm prose-h2:text-sm prose-h3:text-xs prose-ul:my-1.5 prose-ol:my-1.5 prose-li:my-0.5 prose-blockquote:border-l-2 prose-blockquote:border-border prose-blockquote:text-muted-foreground prose-code:rounded prose-code:bg-muted prose-code:px-1 prose-code:py-0.5 prose-code:text-xs prose-code:font-mono prose-code:before:content-none prose-code:after:content-none prose-pre:my-0 prose-pre:p-0 prose-pre:bg-transparent prose-pre:border-0 prose-a:text-primary prose-a:no-underline hover:prose-a:underline prose-strong:font-semibold prose-hr:border-border";
|
|
4239
|
-
const MarkdownText = () => /* @__PURE__ */ jsxRuntime.jsx(
|
|
4240
|
-
reactMarkdown.MarkdownTextPrimitive,
|
|
4241
|
-
{
|
|
4242
|
-
className: MARKDOWN_CLASS,
|
|
4243
|
-
remarkPlugins: [remarkGfm],
|
|
4244
|
-
smooth: true,
|
|
4245
|
-
preprocess: normalizeAthenaMentionHtml,
|
|
4246
|
-
components: {
|
|
4247
|
-
SyntaxHighlighter: CodeBlock,
|
|
4248
|
-
a: MentionLink
|
|
4249
|
-
}
|
|
4250
|
-
}
|
|
4251
|
-
);
|
|
4252
|
-
const UserMessageText = ({ text: text2 }) => /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: parseMentionsInText(text2) });
|
|
4253
|
-
const UserActionBar = () => /* @__PURE__ */ jsxRuntime.jsx(
|
|
4254
|
-
react.ActionBarPrimitive.Root,
|
|
4255
|
-
{
|
|
4256
|
-
autohide: "never",
|
|
4257
|
-
className: "pointer-events-none flex min-h-6 items-center gap-0.5 opacity-0 transition-opacity group-hover/user-message:pointer-events-auto group-hover/user-message:opacity-100 focus-within:pointer-events-auto focus-within:opacity-100",
|
|
4258
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(CopyActionButton, {})
|
|
4259
|
-
}
|
|
4260
|
-
);
|
|
4261
|
-
const UserMessage = () => /* @__PURE__ */ jsxRuntime.jsx(react.MessagePrimitive.Root, { className: "group/user-message mb-3 flex justify-end", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex max-w-[85%] flex-col items-end gap-1", children: [
|
|
4262
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "rounded-2xl rounded-br-md bg-muted px-3.5 py-2 text-sm text-foreground", children: /* @__PURE__ */ jsxRuntime.jsx(react.MessagePrimitive.Content, { components: { Text: UserMessageText } }) }),
|
|
4263
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex min-h-6 items-center gap-1", children: [
|
|
4264
|
-
/* @__PURE__ */ jsxRuntime.jsx(BranchPicker, {}),
|
|
4265
|
-
/* @__PURE__ */ jsxRuntime.jsx(UserActionBar, {})
|
|
4266
|
-
] })
|
|
4267
|
-
] }) });
|
|
4268
|
-
function createAssistantMessage({
|
|
4269
|
-
toolFallback,
|
|
4270
|
-
extraActions,
|
|
4271
|
-
content: Content
|
|
4272
|
-
}) {
|
|
4273
|
-
const AssistantActionBar = () => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
4274
|
-
react.ActionBarPrimitive.Root,
|
|
4275
|
-
{
|
|
4276
|
-
autohide: "never",
|
|
4277
|
-
className: "mt-1 flex min-h-6 items-center gap-0.5",
|
|
4278
|
-
children: [
|
|
4279
|
-
/* @__PURE__ */ jsxRuntime.jsx(CopyActionButton, {}),
|
|
4280
|
-
/* @__PURE__ */ jsxRuntime.jsx(react.ActionBarPrimitive.Reload, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(SmallIconButton, { tooltip: "Regenerate", children: /* @__PURE__ */ jsxRuntime.jsx(scopeRegistry.RefreshCw, { className: "size-3" }) }) }),
|
|
4281
|
-
extraActions
|
|
4282
|
-
]
|
|
4283
|
-
}
|
|
4284
|
-
);
|
|
4285
|
-
const AssistantMessage = () => {
|
|
4286
|
-
const showActions = react.useAuiState(
|
|
4287
|
-
(state) => hasVisibleContent(state.message.content)
|
|
4288
|
-
);
|
|
4289
|
-
return /* @__PURE__ */ jsxRuntime.jsx(react.MessagePrimitive.Root, { className: "group mb-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "max-w-[95%]", children: [
|
|
4290
|
-
Content ? /* @__PURE__ */ jsxRuntime.jsx(Content, {}) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
4291
|
-
react.MessagePrimitive.Content,
|
|
4292
|
-
{
|
|
4293
|
-
components: {
|
|
4294
|
-
Text: MarkdownText,
|
|
4295
|
-
tools: { Fallback: toolFallback }
|
|
4296
|
-
}
|
|
4297
|
-
}
|
|
4298
|
-
),
|
|
4299
|
-
showActions ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex min-h-6 items-center gap-1", children: [
|
|
4300
|
-
/* @__PURE__ */ jsxRuntime.jsx(BranchPicker, {}),
|
|
4301
|
-
/* @__PURE__ */ jsxRuntime.jsx(AssistantActionBar, {})
|
|
4302
|
-
] }) : null
|
|
4303
|
-
] }) });
|
|
4304
|
-
};
|
|
4305
|
-
return AssistantMessage;
|
|
4306
|
-
}
|
|
4307
|
-
const THREAD_PANEL_CLASS = "m-1 flex min-h-0 flex-1 flex-col overflow-hidden rounded-[18px] border border-dashed border-amber-500 bg-background shadow-[0_1px_10px_rgba(54,45,33,0.08)]";
|
|
4308
|
-
const THREAD_HEADER_CLASS = "flex items-center justify-between gap-2 px-3 py-2";
|
|
4309
|
-
const THREAD_HEADER_ACTIONS_CLASS = "flex min-w-0 items-center justify-end gap-1.5";
|
|
4310
|
-
const THREAD_HEADER_PILL_CLASS = "inline-flex h-7 max-w-[170px] items-center gap-1.5 rounded-md border border-neutral-200 bg-white px-2 text-xs font-medium text-neutral-800 shadow-sm";
|
|
4311
|
-
const THREAD_HEADER_ICON_CLASS = "size-[18px]";
|
|
4312
|
-
const COMPOSER_DOCK_CLASS = "bg-background px-2.5 pb-2 pt-1.5";
|
|
4313
|
-
const COMPOSER_SURFACE_CLASS = "relative flex flex-col gap-1 rounded-xl border border-neutral-200 bg-white shadow-[0_2px_10px_rgba(54,45,33,0.08)]";
|
|
4314
|
-
const COMPOSER_EDITOR_ROW_CLASS = "px-2.5 pt-1";
|
|
4315
|
-
const COMPOSER_TOOLBAR_CLASS = "flex items-center gap-1 border-t border-neutral-100 px-2 py-1.5";
|
|
4316
|
-
const THREAD_SCROLL_TO_BOTTOM_CLASS = "inline-flex items-center justify-center rounded-full border bg-background/80 p-1 shadow-sm backdrop-blur transition-opacity hover:bg-accent disabled:invisible";
|
|
4317
|
-
const ComposerStopIcon = () => /* @__PURE__ */ jsxRuntime.jsx(
|
|
4318
|
-
"svg",
|
|
4319
|
-
{
|
|
4320
|
-
"aria-hidden": "true",
|
|
4321
|
-
className: "size-4",
|
|
4322
|
-
viewBox: "0 0 16 16",
|
|
4323
|
-
fill: "currentColor",
|
|
4324
|
-
children: /* @__PURE__ */ jsxRuntime.jsx("rect", { width: "10", height: "10", x: "3", y: "3", rx: "2" })
|
|
4325
|
-
}
|
|
4326
|
-
);
|
|
4327
|
-
const ComposerStopButton = ({ onStop, disabled = false, title = "Stop generation" }) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
4328
|
-
"button",
|
|
4329
|
-
{
|
|
4330
|
-
type: "button",
|
|
4331
|
-
onClick: onStop,
|
|
4332
|
-
disabled,
|
|
4333
|
-
title,
|
|
4334
|
-
className: scopeRegistry.cn(
|
|
4335
|
-
"inline-flex size-8 shrink-0 items-center justify-center rounded-lg bg-foreground text-background shadow-sm transition-colors hover:bg-foreground/80",
|
|
4336
|
-
disabled && "cursor-not-allowed opacity-60"
|
|
4337
|
-
),
|
|
4338
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(ComposerStopIcon, {})
|
|
4339
|
-
}
|
|
4340
|
-
);
|
|
4341
|
-
const ComposerSendButton = ({ action, onSend, disabled = false, title }) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
4342
|
-
"button",
|
|
4343
|
-
{
|
|
4344
|
-
type: "button",
|
|
4345
|
-
onClick: onSend,
|
|
4346
|
-
disabled,
|
|
4347
|
-
title: title ?? (action === "queue" ? "Queue message" : "Send"),
|
|
4348
|
-
className: scopeRegistry.cn(
|
|
4349
|
-
"inline-flex size-8 shrink-0 items-center justify-center rounded-full shadow-sm transition-colors",
|
|
4350
|
-
disabled ? "cursor-not-allowed bg-muted text-muted-foreground opacity-60" : "bg-foreground text-background hover:bg-foreground/80"
|
|
4351
|
-
),
|
|
4352
|
-
children: action === "queue" ? /* @__PURE__ */ jsxRuntime.jsx(ListPlus, { className: "size-4" }) : /* @__PURE__ */ jsxRuntime.jsx(scopeRegistry.ArrowUp, { className: "size-4" })
|
|
4353
|
-
}
|
|
4354
|
-
);
|
|
4355
|
-
function ChatThreadShell({
|
|
4356
|
-
header,
|
|
4357
|
-
banners,
|
|
4358
|
-
viewportOverlay,
|
|
4359
|
-
welcome,
|
|
4360
|
-
components,
|
|
4361
|
-
renderMessages,
|
|
4362
|
-
belowViewport,
|
|
4363
|
-
composer
|
|
4364
|
-
}) {
|
|
4365
|
-
const messages = /* @__PURE__ */ jsxRuntime.jsx(react.ThreadPrimitive.Messages, { components });
|
|
4366
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
4367
|
-
react.ThreadPrimitive.Root,
|
|
4368
|
-
{
|
|
4369
|
-
className: THREAD_PANEL_CLASS,
|
|
4370
|
-
style: { "--thread-max-width": "100%" },
|
|
4371
|
-
children: [
|
|
4372
|
-
header,
|
|
4373
|
-
banners,
|
|
4374
|
-
/* @__PURE__ */ jsxRuntime.jsxs(react.ThreadPrimitive.Viewport, { className: "relative flex flex-1 flex-col overflow-y-auto scroll-smooth", children: [
|
|
4375
|
-
viewportOverlay,
|
|
4376
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex min-h-0 flex-1 flex-col items-center", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full flex-1 px-3 pt-3", children: [
|
|
4377
|
-
welcome != null ? /* @__PURE__ */ jsxRuntime.jsx(react.ThreadPrimitive.Empty, { children: welcome }) : null,
|
|
4378
|
-
renderMessages ? renderMessages(messages) : messages,
|
|
4379
|
-
/* @__PURE__ */ jsxRuntime.jsx(ThreadRunningIndicator, {})
|
|
4380
|
-
] }) }),
|
|
4381
|
-
/* @__PURE__ */ jsxRuntime.jsx(react.ThreadPrimitive.ViewportFooter, { className: "sticky bottom-0", children: /* @__PURE__ */ jsxRuntime.jsx(react.AuiIf, { condition: (state) => !state.thread.isEmpty, children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center pb-0.5", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
4382
|
-
react.ThreadPrimitive.ScrollToBottom,
|
|
4383
|
-
{
|
|
4384
|
-
"aria-label": "Scroll to bottom",
|
|
4385
|
-
title: "Scroll to bottom",
|
|
4386
|
-
className: THREAD_SCROLL_TO_BOTTOM_CLASS,
|
|
4387
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(scopeRegistry.ChevronDown, { className: "size-3.5" })
|
|
4388
|
-
}
|
|
4389
|
-
) }) }) })
|
|
4390
|
-
] }),
|
|
4391
|
-
belowViewport,
|
|
4392
|
-
composer
|
|
4393
|
-
]
|
|
4394
|
-
}
|
|
4395
|
-
);
|
|
4396
|
-
}
|
|
4397
|
-
function ChatComposerDock({
|
|
4398
|
-
aboveSurface,
|
|
4399
|
-
beforeEditor,
|
|
4400
|
-
editor,
|
|
4401
|
-
toolbarStart,
|
|
4402
|
-
toolbarEnd
|
|
4403
|
-
}) {
|
|
4404
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: COMPOSER_DOCK_CLASS, children: [
|
|
4405
|
-
aboveSurface,
|
|
4406
|
-
/* @__PURE__ */ jsxRuntime.jsxs(react.ComposerPrimitive.Root, { className: COMPOSER_SURFACE_CLASS, children: [
|
|
4407
|
-
beforeEditor,
|
|
4408
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: COMPOSER_EDITOR_ROW_CLASS, children: editor }),
|
|
4409
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: COMPOSER_TOOLBAR_CLASS, children: [
|
|
4410
|
-
toolbarStart,
|
|
4411
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1" }),
|
|
4412
|
-
toolbarEnd
|
|
4413
|
-
] })
|
|
4414
|
-
] })
|
|
4415
|
-
] });
|
|
4416
|
-
}
|
|
4417
|
-
function resolveComposerAction({
|
|
4418
|
-
hasDraft,
|
|
4419
|
-
isRunning
|
|
4420
|
-
}) {
|
|
4421
|
-
if (!isRunning) return "send";
|
|
4422
|
-
return hasDraft ? "queue" : "stop";
|
|
4423
|
-
}
|
|
4424
|
-
const ComposerSendOrStop = ({
|
|
4425
|
-
composerRef,
|
|
4426
|
-
hasDraft,
|
|
4427
|
-
disabled = false,
|
|
4428
|
-
sendBlockedReason = null,
|
|
4429
|
-
sendDisabledTitle,
|
|
4430
|
-
stopDisabledTitle,
|
|
4431
|
-
onBeforeSend,
|
|
4432
|
-
onStop
|
|
4433
|
-
}) => {
|
|
4434
|
-
const aui = react.useAui();
|
|
4435
|
-
const isRunning = react.useAuiState(
|
|
4436
|
-
(state) => {
|
|
4437
|
-
var _a;
|
|
4438
|
-
return ((_a = state.optional.thread) == null ? void 0 : _a.isRunning) ?? false;
|
|
4439
|
-
}
|
|
4440
|
-
);
|
|
4441
|
-
const action = resolveComposerAction({ hasDraft, isRunning });
|
|
4442
|
-
const cancelRun = React.useCallback(() => {
|
|
4443
|
-
try {
|
|
4444
|
-
aui.thread.cancelRun();
|
|
4445
|
-
return true;
|
|
4446
|
-
} catch (error) {
|
|
4447
|
-
console.warn("[chat-ui] cancelRun failed", error);
|
|
4448
|
-
return false;
|
|
4449
|
-
}
|
|
4450
|
-
}, [aui]);
|
|
4451
|
-
if (action === "stop") {
|
|
4452
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
4453
|
-
ComposerStopButton,
|
|
4454
|
-
{
|
|
4455
|
-
onStop: () => {
|
|
4456
|
-
if (onStop) {
|
|
4457
|
-
onStop({ cancelRun });
|
|
4458
|
-
} else {
|
|
4459
|
-
cancelRun();
|
|
4460
|
-
}
|
|
4461
|
-
},
|
|
4462
|
-
disabled,
|
|
4463
|
-
title: disabled && stopDisabledTitle ? stopDisabledTitle : void 0
|
|
4464
|
-
}
|
|
4465
|
-
);
|
|
4466
|
-
}
|
|
4467
|
-
const handleSend = async () => {
|
|
4468
|
-
var _a;
|
|
4469
|
-
await (onBeforeSend == null ? void 0 : onBeforeSend({ action }));
|
|
4470
|
-
await ((_a = composerRef.current) == null ? void 0 : _a.submit());
|
|
4471
|
-
};
|
|
4472
|
-
const sendTitle = disabled && sendDisabledTitle ? sendDisabledTitle : sendBlockedReason ?? void 0;
|
|
4473
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
4474
|
-
ComposerSendButton,
|
|
4475
|
-
{
|
|
4476
|
-
action,
|
|
4477
|
-
onSend: () => void handleSend(),
|
|
4478
|
-
disabled: disabled || !hasDraft || sendBlockedReason != null,
|
|
4479
|
-
title: sendTitle
|
|
4480
|
-
}
|
|
4481
|
-
);
|
|
4482
|
-
};
|
|
349
|
+
const Zap = composerSendOrStop.createLucideIcon("zap", __iconNode);
|
|
4483
350
|
function makeMentionUrl(attrs) {
|
|
4484
351
|
if (attrs.type === "tool") {
|
|
4485
352
|
return `mention://tool?name=${encodeURIComponent(attrs.id)}&description=${encodeURIComponent(attrs.description ?? "")}`;
|
|
@@ -4521,7 +388,7 @@ function parseMentionAnchorAttributes({
|
|
|
4521
388
|
assetType: url.searchParams.get("assetType") || ""
|
|
4522
389
|
};
|
|
4523
390
|
}
|
|
4524
|
-
const MentionExtension =
|
|
391
|
+
const MentionExtension = composerSendOrStop.Node.create({
|
|
4525
392
|
name: "mention",
|
|
4526
393
|
group: "inline",
|
|
4527
394
|
inline: true,
|
|
@@ -4572,8 +439,8 @@ const MentionExtension = scopeRegistry.Node.create({
|
|
|
4572
439
|
}
|
|
4573
440
|
];
|
|
4574
441
|
},
|
|
4575
|
-
renderHTML({ node
|
|
4576
|
-
const thumbnailUrl =
|
|
442
|
+
renderHTML({ node, HTMLAttributes }) {
|
|
443
|
+
const thumbnailUrl = node.attrs.thumbnailUrl;
|
|
4577
444
|
const children = [];
|
|
4578
445
|
if (thumbnailUrl) {
|
|
4579
446
|
children.push([
|
|
@@ -4586,38 +453,38 @@ const MentionExtension = scopeRegistry.Node.create({
|
|
|
4586
453
|
}
|
|
4587
454
|
]);
|
|
4588
455
|
}
|
|
4589
|
-
children.push(["span", { class: "mention-chip-text" },
|
|
456
|
+
children.push(["span", { class: "mention-chip-text" }, node.attrs.name]);
|
|
4590
457
|
return [
|
|
4591
458
|
"span",
|
|
4592
|
-
|
|
459
|
+
composerSendOrStop.mergeAttributes(HTMLAttributes, {
|
|
4593
460
|
"data-mention": "",
|
|
4594
|
-
"data-type":
|
|
4595
|
-
"data-name":
|
|
4596
|
-
"data-id":
|
|
4597
|
-
"data-title":
|
|
4598
|
-
"data-url":
|
|
4599
|
-
"data-thumbnail-url":
|
|
4600
|
-
"data-asset-type":
|
|
461
|
+
"data-type": node.attrs.type,
|
|
462
|
+
"data-name": node.attrs.name,
|
|
463
|
+
"data-id": node.attrs.id,
|
|
464
|
+
"data-title": node.attrs.title || "",
|
|
465
|
+
"data-url": node.attrs.url || "",
|
|
466
|
+
"data-thumbnail-url": node.attrs.thumbnailUrl || "",
|
|
467
|
+
"data-asset-type": node.attrs.assetType || "",
|
|
4601
468
|
class: "mention-chip"
|
|
4602
469
|
}),
|
|
4603
470
|
...children
|
|
4604
471
|
];
|
|
4605
472
|
},
|
|
4606
|
-
renderText({ node
|
|
473
|
+
renderText({ node }) {
|
|
4607
474
|
const url = makeMentionUrl({
|
|
4608
|
-
id:
|
|
4609
|
-
type:
|
|
4610
|
-
name:
|
|
4611
|
-
title:
|
|
4612
|
-
url:
|
|
4613
|
-
description:
|
|
4614
|
-
thumbnailUrl:
|
|
4615
|
-
assetType:
|
|
475
|
+
id: node.attrs.id,
|
|
476
|
+
type: node.attrs.type,
|
|
477
|
+
name: node.attrs.name,
|
|
478
|
+
title: node.attrs.title,
|
|
479
|
+
url: node.attrs.url,
|
|
480
|
+
description: node.attrs.description,
|
|
481
|
+
thumbnailUrl: node.attrs.thumbnailUrl,
|
|
482
|
+
assetType: node.attrs.assetType
|
|
4616
483
|
});
|
|
4617
|
-
return `[@${
|
|
484
|
+
return `[@${node.attrs.name}](${url})`;
|
|
4618
485
|
}
|
|
4619
486
|
});
|
|
4620
|
-
const MentionSuggestionsExtension =
|
|
487
|
+
const MentionSuggestionsExtension = composerSendOrStop.Extension.create({
|
|
4621
488
|
name: "mentionSuggestions",
|
|
4622
489
|
addOptions() {
|
|
4623
490
|
return {
|
|
@@ -4628,7 +495,7 @@ const MentionSuggestionsExtension = scopeRegistry.Extension.create({
|
|
|
4628
495
|
addProseMirrorPlugins() {
|
|
4629
496
|
const callbacks = this.options.callbacks;
|
|
4630
497
|
return [
|
|
4631
|
-
|
|
498
|
+
composerSendOrStop.Suggestion({
|
|
4632
499
|
editor: this.editor,
|
|
4633
500
|
char: "@",
|
|
4634
501
|
allowSpaces: false,
|
|
@@ -4683,10 +550,10 @@ const MentionSuggestionsExtension = scopeRegistry.Extension.create({
|
|
|
4683
550
|
}
|
|
4684
551
|
});
|
|
4685
552
|
const MentionSuggestionPopup = ({ clientRect, children }) => {
|
|
4686
|
-
const { refs, floatingStyles } =
|
|
553
|
+
const { refs, floatingStyles } = composerSendOrStop.useFloating$1({
|
|
4687
554
|
placement: "bottom-start",
|
|
4688
|
-
middleware: [
|
|
4689
|
-
whileElementsMounted:
|
|
555
|
+
middleware: [composerSendOrStop.offset(10), composerSendOrStop.flip(), composerSendOrStop.shift({ padding: 8 })],
|
|
556
|
+
whileElementsMounted: composerSendOrStop.autoUpdate
|
|
4690
557
|
});
|
|
4691
558
|
React.useEffect(() => {
|
|
4692
559
|
if (clientRect) {
|
|
@@ -4695,7 +562,7 @@ const MentionSuggestionPopup = ({ clientRect, children }) => {
|
|
|
4695
562
|
});
|
|
4696
563
|
}
|
|
4697
564
|
}, [clientRect, refs]);
|
|
4698
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
565
|
+
return /* @__PURE__ */ jsxRuntime.jsx(composerSendOrStop.FloatingPortal, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
4699
566
|
"div",
|
|
4700
567
|
{
|
|
4701
568
|
ref: refs.setFloating,
|
|
@@ -4711,11 +578,11 @@ function selectItems(store, scope, query, _targetCount, parentScope) {
|
|
|
4711
578
|
const state = store.state;
|
|
4712
579
|
const scopeId = typeof scope === "string" ? scope : scope.id;
|
|
4713
580
|
const parentScopeId = parentScope ? typeof parentScope === "string" ? parentScope : parentScope.id : void 0;
|
|
4714
|
-
const items =
|
|
581
|
+
const items = composerSendOrStop.getFilteredItems(state.cache, scopeId, query);
|
|
4715
582
|
let isFetching = false;
|
|
4716
583
|
let hasMore = true;
|
|
4717
584
|
try {
|
|
4718
|
-
const fetchState =
|
|
585
|
+
const fetchState = composerSendOrStop.getFetchState(state.registry, scopeId, query, parentScopeId);
|
|
4719
586
|
isFetching = fetchState.isFetching;
|
|
4720
587
|
hasMore = fetchState.hasNextPage;
|
|
4721
588
|
} catch {
|
|
@@ -4729,17 +596,17 @@ function triggerFetchIfNeeded(store, scope, query, _targetCount, parentScope) {
|
|
|
4729
596
|
const state = store.state;
|
|
4730
597
|
let entry;
|
|
4731
598
|
try {
|
|
4732
|
-
entry =
|
|
599
|
+
entry = composerSendOrStop.getEntry(state.registry, scopeId, parentScopeId);
|
|
4733
600
|
} catch {
|
|
4734
601
|
return;
|
|
4735
602
|
}
|
|
4736
|
-
const fetchState =
|
|
603
|
+
const fetchState = composerSendOrStop.getFetchState(state.registry, scopeId, query, parentScopeId);
|
|
4737
604
|
if (fetchState.isFetching || !fetchState.hasNextPage || fetchState.error) {
|
|
4738
605
|
return;
|
|
4739
606
|
}
|
|
4740
607
|
const meta = fetchState.meta || {};
|
|
4741
608
|
if ((meta.fetchAttempts || 0) >= 10) return;
|
|
4742
|
-
|
|
609
|
+
composerSendOrStop.updateFetchState(state.registry, scopeId, query, { isFetching: true }, parentScopeId);
|
|
4743
610
|
store.setState((prev) => ({ ...prev }));
|
|
4744
611
|
const sourceFn = entry.sourceFn;
|
|
4745
612
|
const sourceConfig = entry.sourceConfig;
|
|
@@ -4751,13 +618,13 @@ function triggerFetchIfNeeded(store, scope, query, _targetCount, parentScope) {
|
|
|
4751
618
|
}).then((result) => {
|
|
4752
619
|
var _a, _b;
|
|
4753
620
|
const currentState = store.state;
|
|
4754
|
-
|
|
621
|
+
composerSendOrStop.addItems(currentState.cache, result.items, scopeId);
|
|
4755
622
|
if (result.sources) {
|
|
4756
623
|
for (const src of result.sources) {
|
|
4757
624
|
try {
|
|
4758
|
-
|
|
625
|
+
composerSendOrStop.getEntry(currentState.registry, src.scope);
|
|
4759
626
|
} catch {
|
|
4760
|
-
|
|
627
|
+
composerSendOrStop.registerSource(
|
|
4761
628
|
currentState.registry,
|
|
4762
629
|
src.scope,
|
|
4763
630
|
src.sourceFn,
|
|
@@ -4769,13 +636,13 @@ function triggerFetchIfNeeded(store, scope, query, _targetCount, parentScope) {
|
|
|
4769
636
|
}
|
|
4770
637
|
if (result.bindings) {
|
|
4771
638
|
for (const binding of result.bindings) {
|
|
4772
|
-
|
|
639
|
+
composerSendOrStop.bindScopes(currentState.registry, binding.browseScope, binding.searchScope);
|
|
4773
640
|
}
|
|
4774
641
|
}
|
|
4775
642
|
const currentMeta = fetchState.meta || {};
|
|
4776
643
|
const consumed = ((_a = result.pagination) == null ? void 0 : _a.consumedCount) ?? result.items.length;
|
|
4777
644
|
const newValidated = (currentMeta.validatedCount || 0) + consumed;
|
|
4778
|
-
|
|
645
|
+
composerSendOrStop.updateFetchState(
|
|
4779
646
|
currentState.registry,
|
|
4780
647
|
scopeId,
|
|
4781
648
|
query,
|
|
@@ -4800,7 +667,7 @@ function triggerFetchIfNeeded(store, scope, query, _targetCount, parentScope) {
|
|
|
4800
667
|
const currentMeta = fetchState.meta || {};
|
|
4801
668
|
const errorAttempts = (currentMeta.errorAttempts || 0) + 1;
|
|
4802
669
|
const retriable = errorAttempts < MAX_ERROR_RETRIES;
|
|
4803
|
-
|
|
670
|
+
composerSendOrStop.updateFetchState(
|
|
4804
671
|
currentState.registry,
|
|
4805
672
|
scopeId,
|
|
4806
673
|
query,
|
|
@@ -4821,7 +688,7 @@ function useMenuItems(store, options) {
|
|
|
4821
688
|
React.useEffect(() => {
|
|
4822
689
|
setTargetCount(minItems);
|
|
4823
690
|
}, [scope, query, minItems]);
|
|
4824
|
-
const snapshot =
|
|
691
|
+
const snapshot = composerSendOrStop.useStore(
|
|
4825
692
|
store,
|
|
4826
693
|
() => selectItems(store, scope, query, targetCount, parentScope)
|
|
4827
694
|
);
|
|
@@ -4891,52 +758,52 @@ const MentionMenuSection = {
|
|
|
4891
758
|
};
|
|
4892
759
|
const ICON_MAP = {
|
|
4893
760
|
// General
|
|
4894
|
-
file:
|
|
4895
|
-
"file-text":
|
|
761
|
+
file: composerSendOrStop.File,
|
|
762
|
+
"file-text": composerSendOrStop.FileText,
|
|
4896
763
|
"file-code": FileCode,
|
|
4897
|
-
folder:
|
|
4898
|
-
"folder-kanban":
|
|
4899
|
-
globe:
|
|
4900
|
-
search:
|
|
764
|
+
folder: composerSendOrStop.Folder,
|
|
765
|
+
"folder-kanban": composerSendOrStop.FolderKanban,
|
|
766
|
+
globe: composerSendOrStop.Globe,
|
|
767
|
+
search: composerSendOrStop.Search,
|
|
4901
768
|
star: Star,
|
|
4902
|
-
users:
|
|
769
|
+
users: composerSendOrStop.Users,
|
|
4903
770
|
user: User,
|
|
4904
|
-
wrench:
|
|
4905
|
-
package:
|
|
771
|
+
wrench: composerSendOrStop.Wrench,
|
|
772
|
+
package: composerSendOrStop.Package,
|
|
4906
773
|
"building-2": Building2,
|
|
4907
|
-
"hard-drive":
|
|
4908
|
-
"layout-grid":
|
|
774
|
+
"hard-drive": composerSendOrStop.HardDrive,
|
|
775
|
+
"layout-grid": composerSendOrStop.LayoutGrid,
|
|
4909
776
|
zap: Zap,
|
|
4910
777
|
eye: Eye,
|
|
4911
778
|
// Chrome tools
|
|
4912
|
-
camera:
|
|
779
|
+
camera: composerSendOrStop.Camera,
|
|
4913
780
|
keyboard: Keyboard,
|
|
4914
|
-
code:
|
|
4915
|
-
monitor:
|
|
781
|
+
code: composerSendOrStop.Code,
|
|
782
|
+
monitor: composerSendOrStop.Monitor,
|
|
4916
783
|
// Asset types
|
|
4917
|
-
image:
|
|
784
|
+
image: composerSendOrStop.Image,
|
|
4918
785
|
video: Video,
|
|
4919
786
|
headphones: Headphones,
|
|
4920
787
|
mic: Mic,
|
|
4921
|
-
mail:
|
|
4922
|
-
calendar:
|
|
788
|
+
mail: composerSendOrStop.Mail,
|
|
789
|
+
calendar: composerSendOrStop.Calendar,
|
|
4923
790
|
phone: Phone,
|
|
4924
|
-
database:
|
|
4925
|
-
table:
|
|
4926
|
-
sheet:
|
|
791
|
+
database: composerSendOrStop.Database,
|
|
792
|
+
table: composerSendOrStop.Table,
|
|
793
|
+
sheet: composerSendOrStop.Sheet,
|
|
4927
794
|
palette: Palette,
|
|
4928
795
|
"pen-tool": PenTool,
|
|
4929
796
|
layout: PanelsTopLeft,
|
|
4930
797
|
"layout-dashboard": LayoutDashboard,
|
|
4931
798
|
library: Library,
|
|
4932
|
-
"book-open":
|
|
799
|
+
"book-open": composerSendOrStop.BookOpen,
|
|
4933
800
|
sparkles: Sparkles,
|
|
4934
801
|
"check-square": SquareCheckBig,
|
|
4935
802
|
key: Key,
|
|
4936
803
|
smartphone: Smartphone,
|
|
4937
804
|
cloud: Cloud,
|
|
4938
|
-
workflow:
|
|
4939
|
-
presentation:
|
|
805
|
+
workflow: composerSendOrStop.Workflow,
|
|
806
|
+
presentation: composerSendOrStop.FileText
|
|
4940
807
|
// Fallback for presentation type
|
|
4941
808
|
};
|
|
4942
809
|
function MentionIcon({
|
|
@@ -4951,7 +818,7 @@ function MentionIcon({
|
|
|
4951
818
|
const Icon = fallbackIcon ? ICON_MAP[fallbackIcon] : void 0;
|
|
4952
819
|
if (Icon) return /* @__PURE__ */ jsxRuntime.jsx(Icon, { className });
|
|
4953
820
|
if (fallbackIcon) return /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm flex-shrink-0", children: fallbackIcon });
|
|
4954
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
821
|
+
return /* @__PURE__ */ jsxRuntime.jsx(composerSendOrStop.File, { className });
|
|
4955
822
|
}
|
|
4956
823
|
function MenuItemRow({
|
|
4957
824
|
item,
|
|
@@ -4969,7 +836,7 @@ function MenuItemRow({
|
|
|
4969
836
|
tabIndex: -1,
|
|
4970
837
|
onClick,
|
|
4971
838
|
onMouseEnter,
|
|
4972
|
-
className:
|
|
839
|
+
className: composerSendOrStop.cn(
|
|
4973
840
|
"mention-item flex items-center justify-between gap-2 px-2 py-1.5 rounded cursor-pointer transition-colors",
|
|
4974
841
|
"hover:bg-gray-100",
|
|
4975
842
|
item.menuSection === MentionMenuSection.CURRENT_WEBPAGE && !isSelected && "bg-sky-50/70",
|
|
@@ -5171,7 +1038,7 @@ function getSelectedIndex(state) {
|
|
|
5171
1038
|
}
|
|
5172
1039
|
function useMenuNavigation() {
|
|
5173
1040
|
const [store] = React.useState(() => {
|
|
5174
|
-
const baseStore = new
|
|
1041
|
+
const baseStore = new composerSendOrStop.Store({
|
|
5175
1042
|
scopeStack: [{ scope: "root", selectedIndex: 0 }],
|
|
5176
1043
|
query: "",
|
|
5177
1044
|
isActive: false
|
|
@@ -5251,14 +1118,14 @@ function clearTextAfterTrigger(editor) {
|
|
|
5251
1118
|
const MentionSuggestionList = React.forwardRef(({ store, editor, query, command, closeMenu }, ref) => {
|
|
5252
1119
|
const [selectedIndexOverride, setSelectedIndexOverride] = React.useState(null);
|
|
5253
1120
|
const navStore = useMenuNavigation();
|
|
5254
|
-
const currentScopeId =
|
|
5255
|
-
const navSelectedIndex =
|
|
1121
|
+
const currentScopeId = composerSendOrStop.useStore(navStore, (s) => getCurrentScope(s));
|
|
1122
|
+
const navSelectedIndex = composerSendOrStop.useStore(navStore, (s) => getSelectedIndex(s));
|
|
5256
1123
|
const selectedIndex = selectedIndexOverride ?? navSelectedIndex;
|
|
5257
|
-
const scopeStack =
|
|
1124
|
+
const scopeStack = composerSendOrStop.useStore(navStore, (s) => s.scopeStack);
|
|
5258
1125
|
let effectiveScopeId = currentScopeId;
|
|
5259
1126
|
if (query) {
|
|
5260
1127
|
try {
|
|
5261
|
-
const searchScope =
|
|
1128
|
+
const searchScope = composerSendOrStop.getSearchScope(store.state.registry, currentScopeId);
|
|
5262
1129
|
if (searchScope) {
|
|
5263
1130
|
effectiveScopeId = searchScope;
|
|
5264
1131
|
}
|
|
@@ -5355,8 +1222,8 @@ function assetToMenuItem(asset) {
|
|
|
5355
1222
|
id: asset.id,
|
|
5356
1223
|
name: asset.title || "Untitled",
|
|
5357
1224
|
type: isFolder ? "folder" : "asset",
|
|
5358
|
-
thumbnailUrl: assetTypeToThumb(asset.athenaOriginalType),
|
|
5359
|
-
fallbackIcon: assetTypeToIcon(asset.athenaOriginalType),
|
|
1225
|
+
thumbnailUrl: composerSendOrStop.assetTypeToThumb(asset.athenaOriginalType),
|
|
1226
|
+
fallbackIcon: composerSendOrStop.assetTypeToIcon(asset.athenaOriginalType),
|
|
5360
1227
|
navigatesToScope: isFolder ? asset.id : void 0,
|
|
5361
1228
|
visibleInScopes: /* @__PURE__ */ new Set(),
|
|
5362
1229
|
updatedAt: asset.updatedAt ?? void 0,
|
|
@@ -5382,9 +1249,9 @@ async function querySimpleSearch(auth, opts) {
|
|
|
5382
1249
|
sort: { field: "UPDATED_AT", direction: "DESC" },
|
|
5383
1250
|
filterColumns: { isArchived: false, isHidden: false }
|
|
5384
1251
|
};
|
|
5385
|
-
const data = await fetchGraphQL(
|
|
1252
|
+
const data = await composerSendOrStop.fetchGraphQL(
|
|
5386
1253
|
auth,
|
|
5387
|
-
SIMPLE_SEARCH_QUERY,
|
|
1254
|
+
composerSendOrStop.SIMPLE_SEARCH_QUERY,
|
|
5388
1255
|
{ input }
|
|
5389
1256
|
);
|
|
5390
1257
|
const assets = ((_b = data.simpleSearch) == null ? void 0 : _b.assets) || [];
|
|
@@ -5415,7 +1282,7 @@ function webpageToMenuItem(webpage) {
|
|
|
5415
1282
|
id: `webpage-tab-${webpage.tabId}`,
|
|
5416
1283
|
name: webpage.isCurrent ? "This webpage" : webpage.title,
|
|
5417
1284
|
type: "tab",
|
|
5418
|
-
thumbnailUrl: assetTypeToThumb("web_page"),
|
|
1285
|
+
thumbnailUrl: composerSendOrStop.assetTypeToThumb("web_page"),
|
|
5419
1286
|
fallbackIcon: "globe",
|
|
5420
1287
|
visibleInScopes: /* @__PURE__ */ new Set(["root"]),
|
|
5421
1288
|
description: webpageDescription(webpage),
|
|
@@ -5477,9 +1344,9 @@ const fetchFavorites = async (context) => {
|
|
|
5477
1344
|
const limit = sourceConfig.limit ?? 50;
|
|
5478
1345
|
const meta = fetchState.meta || {};
|
|
5479
1346
|
const offset = meta.validatedCount || 0;
|
|
5480
|
-
const data = await fetchGraphQL(
|
|
1347
|
+
const data = await composerSendOrStop.fetchGraphQL(
|
|
5481
1348
|
sourceConfig.auth,
|
|
5482
|
-
PAGINATED_ASSETS_QUERY,
|
|
1349
|
+
composerSendOrStop.PAGINATED_ASSETS_QUERY,
|
|
5483
1350
|
{
|
|
5484
1351
|
limit,
|
|
5485
1352
|
offset,
|
|
@@ -5521,9 +1388,9 @@ const fetchFolderContents = async (context) => {
|
|
|
5521
1388
|
const meta = fetchState.meta || {};
|
|
5522
1389
|
const offset = meta.validatedCount || 0;
|
|
5523
1390
|
const parentFolderId = scope === "internal_drive" ? null : scope;
|
|
5524
|
-
const data = await fetchGraphQL(
|
|
1391
|
+
const data = await composerSendOrStop.fetchGraphQL(
|
|
5525
1392
|
sourceConfig.auth,
|
|
5526
|
-
PAGINATED_ASSETS_QUERY,
|
|
1393
|
+
composerSendOrStop.PAGINATED_ASSETS_QUERY,
|
|
5527
1394
|
{
|
|
5528
1395
|
limit,
|
|
5529
1396
|
offset,
|
|
@@ -5571,9 +1438,9 @@ const fetchTeam = async (context) => {
|
|
|
5571
1438
|
if (!auth.workspaceId) {
|
|
5572
1439
|
return { items: [], pagination: { hasMore: false } };
|
|
5573
1440
|
}
|
|
5574
|
-
const data = await fetchGraphQL(
|
|
1441
|
+
const data = await composerSendOrStop.fetchGraphQL(
|
|
5575
1442
|
auth,
|
|
5576
|
-
WORKSPACE_MEMBERS_QUERY,
|
|
1443
|
+
composerSendOrStop.WORKSPACE_MEMBERS_QUERY,
|
|
5577
1444
|
{ workspaceId: auth.workspaceId }
|
|
5578
1445
|
);
|
|
5579
1446
|
const members = data.getUsersInWorkspace || [];
|
|
@@ -5658,17 +1525,17 @@ function buildStore({
|
|
|
5658
1525
|
getWebpages,
|
|
5659
1526
|
rootCategories
|
|
5660
1527
|
}) {
|
|
5661
|
-
const registry =
|
|
5662
|
-
const cache =
|
|
5663
|
-
|
|
1528
|
+
const registry = composerSendOrStop.createScopeRegistry();
|
|
1529
|
+
const cache = composerSendOrStop.createItemCache();
|
|
1530
|
+
composerSendOrStop.registerSource(registry, "root", transformRootCategories, {
|
|
5664
1531
|
categories: [...rootCategories],
|
|
5665
1532
|
getWebpages
|
|
5666
1533
|
});
|
|
5667
|
-
|
|
5668
|
-
|
|
5669
|
-
|
|
5670
|
-
|
|
5671
|
-
|
|
1534
|
+
composerSendOrStop.registerSource(registry, "global_search", fetchGlobalSearch, { auth });
|
|
1535
|
+
composerSendOrStop.bindScopes(registry, "root", "global_search");
|
|
1536
|
+
composerSendOrStop.registerSource(registry, "athena_assets", fetchAssets, { auth, limit: 50 });
|
|
1537
|
+
composerSendOrStop.registerSource(registry, "favorites", fetchFavorites, { auth, limit: 50 });
|
|
1538
|
+
composerSendOrStop.registerSource(
|
|
5672
1539
|
registry,
|
|
5673
1540
|
"athena_folders",
|
|
5674
1541
|
fetchFolders,
|
|
@@ -5676,26 +1543,26 @@ function buildStore({
|
|
|
5676
1543
|
true
|
|
5677
1544
|
/* isFlat */
|
|
5678
1545
|
);
|
|
5679
|
-
|
|
5680
|
-
|
|
1546
|
+
composerSendOrStop.registerSource(registry, "internal_drive", fetchFolderContents, { auth, limit: 50 });
|
|
1547
|
+
composerSendOrStop.registerSource(registry, "athena_projects", fetchTypedAssets, {
|
|
5681
1548
|
auth,
|
|
5682
1549
|
includeOnlyTypes: ["project"],
|
|
5683
1550
|
limit: 50
|
|
5684
1551
|
});
|
|
5685
|
-
|
|
1552
|
+
composerSendOrStop.registerSource(registry, "athena_browse_profiles", fetchTypedAssets, {
|
|
5686
1553
|
auth,
|
|
5687
1554
|
includeOnlyTypes: ["browse_profile"],
|
|
5688
1555
|
limit: 50
|
|
5689
1556
|
});
|
|
5690
|
-
|
|
5691
|
-
|
|
5692
|
-
return new
|
|
1557
|
+
composerSendOrStop.registerSource(registry, "team", fetchTeam, { auth });
|
|
1558
|
+
composerSendOrStop.registerSource(registry, "drive_catalogs", fetchDrives, { auth });
|
|
1559
|
+
return new composerSendOrStop.Store({ registry, cache });
|
|
5693
1560
|
}
|
|
5694
1561
|
function useMentionSuggestions({
|
|
5695
1562
|
webpages,
|
|
5696
1563
|
rootCategories = ROOT_MENTION_CATEGORIES
|
|
5697
1564
|
}) {
|
|
5698
|
-
const auth = useMentionAuth();
|
|
1565
|
+
const auth = composerSendOrStop.useMentionAuth();
|
|
5699
1566
|
const webpagesRef = React.useRef(webpages);
|
|
5700
1567
|
webpagesRef.current = webpages;
|
|
5701
1568
|
const store = React.useMemo(
|
|
@@ -5762,7 +1629,7 @@ class PendingAttachmentUploads {
|
|
|
5762
1629
|
}
|
|
5763
1630
|
}
|
|
5764
1631
|
}
|
|
5765
|
-
const SubmitKeybind =
|
|
1632
|
+
const SubmitKeybind = composerSendOrStop.Extension.create({
|
|
5766
1633
|
name: "submitKeybind",
|
|
5767
1634
|
priority: 1e3,
|
|
5768
1635
|
addOptions() {
|
|
@@ -5829,10 +1696,10 @@ const MENTION_STYLES = `
|
|
|
5829
1696
|
height: 0;
|
|
5830
1697
|
}
|
|
5831
1698
|
`;
|
|
5832
|
-
function plainTextToTiptapContent(
|
|
1699
|
+
function plainTextToTiptapContent(text) {
|
|
5833
1700
|
return {
|
|
5834
1701
|
type: "doc",
|
|
5835
|
-
content:
|
|
1702
|
+
content: text.split("\n").map((line) => ({
|
|
5836
1703
|
type: "paragraph",
|
|
5837
1704
|
...line.length > 0 ? { content: [{ type: "text", text: line }] } : {}
|
|
5838
1705
|
}))
|
|
@@ -5878,10 +1745,10 @@ const TiptapComposer = React.forwardRef(({ placeholder = "Message Athena... (typ
|
|
|
5878
1745
|
await pendingUploadsRef.current.waitForIdle();
|
|
5879
1746
|
const ed = editorRef.current;
|
|
5880
1747
|
if (!ed) return;
|
|
5881
|
-
const
|
|
5882
|
-
if (!
|
|
1748
|
+
const text = ed.getText({ blockSeparator: "\n" }).trim();
|
|
1749
|
+
if (!text) return;
|
|
5883
1750
|
if (!composerInput.canSend) return;
|
|
5884
|
-
composerInput.setText(
|
|
1751
|
+
composerInput.setText(text);
|
|
5885
1752
|
composerInput.send({ steer: false });
|
|
5886
1753
|
ed.commands.clearContent();
|
|
5887
1754
|
onDraftStateChange == null ? void 0 : onDraftStateChange(false);
|
|
@@ -5938,10 +1805,10 @@ const TiptapComposer = React.forwardRef(({ placeholder = "Message Athena... (typ
|
|
|
5938
1805
|
},
|
|
5939
1806
|
[addAttachment]
|
|
5940
1807
|
);
|
|
5941
|
-
const editor =
|
|
1808
|
+
const editor = composerSendOrStop.useEditor({
|
|
5942
1809
|
editable: !disabled,
|
|
5943
1810
|
extensions: [
|
|
5944
|
-
|
|
1811
|
+
composerSendOrStop.StarterKit.configure({
|
|
5945
1812
|
heading: false,
|
|
5946
1813
|
blockquote: false,
|
|
5947
1814
|
bulletList: false,
|
|
@@ -5949,7 +1816,7 @@ const TiptapComposer = React.forwardRef(({ placeholder = "Message Athena... (typ
|
|
|
5949
1816
|
codeBlock: false,
|
|
5950
1817
|
horizontalRule: false
|
|
5951
1818
|
}),
|
|
5952
|
-
|
|
1819
|
+
composerSendOrStop.Placeholder.configure({ placeholder }),
|
|
5953
1820
|
MentionExtension,
|
|
5954
1821
|
MentionSuggestionsExtension.configure({
|
|
5955
1822
|
store,
|
|
@@ -6019,7 +1886,7 @@ const TiptapComposer = React.forwardRef(({ placeholder = "Message Athena... (typ
|
|
|
6019
1886
|
className: "flex-1 min-w-0",
|
|
6020
1887
|
"aria-label": "Message composer",
|
|
6021
1888
|
"aria-disabled": disabled,
|
|
6022
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1889
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(composerSendOrStop.EditorContent, { editor })
|
|
6023
1890
|
}
|
|
6024
1891
|
),
|
|
6025
1892
|
popupOpen && popupProps && editor && /* @__PURE__ */ jsxRuntime.jsx(MentionSuggestionPopup, { clientRect: popupProps.clientRect, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -6101,7 +1968,7 @@ const SignInTextField = ({ label, placeholder, value, onChange, type = "text", c
|
|
|
6101
1968
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
6102
1969
|
"input",
|
|
6103
1970
|
{
|
|
6104
|
-
className:
|
|
1971
|
+
className: composerSendOrStop.cn(
|
|
6105
1972
|
"h-9 w-full rounded-md border bg-background px-2.5 text-xs outline-none focus:ring-2 focus:ring-ring/20",
|
|
6106
1973
|
className
|
|
6107
1974
|
),
|
|
@@ -6155,23 +2022,45 @@ const SignInConsent = ({ checked, onChange, children }) => /* @__PURE__ */ jsxRu
|
|
|
6155
2022
|
),
|
|
6156
2023
|
/* @__PURE__ */ jsxRuntime.jsx("span", { children })
|
|
6157
2024
|
] });
|
|
6158
|
-
exports.BranchPicker = BranchPicker;
|
|
6159
|
-
exports.COMPOSER_DOCK_CLASS = COMPOSER_DOCK_CLASS;
|
|
6160
|
-
exports.COMPOSER_EDITOR_ROW_CLASS = COMPOSER_EDITOR_ROW_CLASS;
|
|
6161
|
-
exports.COMPOSER_SURFACE_CLASS = COMPOSER_SURFACE_CLASS;
|
|
6162
|
-
exports.COMPOSER_TOOLBAR_CLASS = COMPOSER_TOOLBAR_CLASS;
|
|
6163
|
-
exports.ChatComposerDock = ChatComposerDock;
|
|
6164
|
-
exports.ChatThreadShell = ChatThreadShell;
|
|
6165
|
-
exports.ComposerSendButton = ComposerSendButton;
|
|
6166
|
-
exports.ComposerSendOrStop = ComposerSendOrStop;
|
|
6167
|
-
exports.ComposerStopButton = ComposerStopButton;
|
|
6168
|
-
exports.IconButton = IconButton;
|
|
6169
|
-
exports.MarkdownText = MarkdownText;
|
|
6170
|
-
exports.MentionAuthCtx = MentionAuthCtx;
|
|
6171
|
-
exports.MentionChip = MentionChip;
|
|
2025
|
+
exports.BranchPicker = composerSendOrStop.BranchPicker;
|
|
2026
|
+
exports.COMPOSER_DOCK_CLASS = composerSendOrStop.COMPOSER_DOCK_CLASS;
|
|
2027
|
+
exports.COMPOSER_EDITOR_ROW_CLASS = composerSendOrStop.COMPOSER_EDITOR_ROW_CLASS;
|
|
2028
|
+
exports.COMPOSER_SURFACE_CLASS = composerSendOrStop.COMPOSER_SURFACE_CLASS;
|
|
2029
|
+
exports.COMPOSER_TOOLBAR_CLASS = composerSendOrStop.COMPOSER_TOOLBAR_CLASS;
|
|
2030
|
+
exports.ChatComposerDock = composerSendOrStop.ChatComposerDock;
|
|
2031
|
+
exports.ChatThreadShell = composerSendOrStop.ChatThreadShell;
|
|
2032
|
+
exports.ComposerSendButton = composerSendOrStop.ComposerSendButton;
|
|
2033
|
+
exports.ComposerSendOrStop = composerSendOrStop.ComposerSendOrStop;
|
|
2034
|
+
exports.ComposerStopButton = composerSendOrStop.ComposerStopButton;
|
|
2035
|
+
exports.IconButton = composerSendOrStop.IconButton;
|
|
2036
|
+
exports.MarkdownText = composerSendOrStop.MarkdownText;
|
|
2037
|
+
exports.MentionAuthCtx = composerSendOrStop.MentionAuthCtx;
|
|
2038
|
+
exports.MentionChip = composerSendOrStop.MentionChip;
|
|
2039
|
+
exports.MentionLink = composerSendOrStop.MentionLink;
|
|
2040
|
+
exports.SIMPLE_SEARCH_QUERY = composerSendOrStop.SIMPLE_SEARCH_QUERY;
|
|
2041
|
+
exports.SmallIconButton = composerSendOrStop.SmallIconButton;
|
|
2042
|
+
exports.THREAD_HEADER_ACTIONS_CLASS = composerSendOrStop.THREAD_HEADER_ACTIONS_CLASS;
|
|
2043
|
+
exports.THREAD_HEADER_CLASS = composerSendOrStop.THREAD_HEADER_CLASS;
|
|
2044
|
+
exports.THREAD_HEADER_ICON_CLASS = composerSendOrStop.THREAD_HEADER_ICON_CLASS;
|
|
2045
|
+
exports.THREAD_HEADER_PILL_CLASS = composerSendOrStop.THREAD_HEADER_PILL_CLASS;
|
|
2046
|
+
exports.THREAD_PANEL_CLASS = composerSendOrStop.THREAD_PANEL_CLASS;
|
|
2047
|
+
exports.THREAD_SCROLL_TO_BOTTOM_CLASS = composerSendOrStop.THREAD_SCROLL_TO_BOTTOM_CLASS;
|
|
2048
|
+
exports.TextShimmerLoader = composerSendOrStop.TextShimmerLoader;
|
|
2049
|
+
exports.ThreadRunningIndicator = composerSendOrStop.ThreadRunningIndicator;
|
|
2050
|
+
exports.UserMessage = composerSendOrStop.UserMessage;
|
|
2051
|
+
exports.assetTypeToIcon = composerSendOrStop.assetTypeToIcon;
|
|
2052
|
+
exports.assetTypeToThumb = composerSendOrStop.assetTypeToThumb;
|
|
2053
|
+
exports.configureAssetIconBasePath = composerSendOrStop.configureAssetIconBasePath;
|
|
2054
|
+
exports.createAssistantMessage = composerSendOrStop.createAssistantMessage;
|
|
2055
|
+
exports.createOlympusAssetUrl = composerSendOrStop.createOlympusAssetUrl;
|
|
2056
|
+
exports.fetchGraphQL = composerSendOrStop.fetchGraphQL;
|
|
2057
|
+
exports.normalizeAthenaMentionHtml = composerSendOrStop.normalizeAthenaMentionHtml;
|
|
2058
|
+
exports.parseMentionUrl = composerSendOrStop.parseMentionUrl;
|
|
2059
|
+
exports.parseMentionsInText = composerSendOrStop.parseMentionsInText;
|
|
2060
|
+
exports.resolveComposerAction = composerSendOrStop.resolveComposerAction;
|
|
2061
|
+
exports.useMentionAuth = composerSendOrStop.useMentionAuth;
|
|
6172
2062
|
exports.MentionExtension = MentionExtension;
|
|
6173
2063
|
exports.MentionIcon = MentionIcon;
|
|
6174
|
-
exports.MentionLink = MentionLink;
|
|
6175
2064
|
exports.MentionMenuSection = MentionMenuSection;
|
|
6176
2065
|
exports.MentionSuggestionList = MentionSuggestionList;
|
|
6177
2066
|
exports.MentionSuggestionPopup = MentionSuggestionPopup;
|
|
@@ -6179,39 +2068,17 @@ exports.MentionSuggestionsExtension = MentionSuggestionsExtension;
|
|
|
6179
2068
|
exports.MenuList = MenuList;
|
|
6180
2069
|
exports.PendingAttachmentUploads = PendingAttachmentUploads;
|
|
6181
2070
|
exports.ROOT_MENTION_CATEGORIES = ROOT_MENTION_CATEGORIES;
|
|
6182
|
-
exports.SIMPLE_SEARCH_QUERY = SIMPLE_SEARCH_QUERY;
|
|
6183
2071
|
exports.SignInCard = SignInCard;
|
|
6184
2072
|
exports.SignInConsent = SignInConsent;
|
|
6185
2073
|
exports.SignInFallbackSection = SignInFallbackSection;
|
|
6186
2074
|
exports.SignInSecondaryButton = SignInSecondaryButton;
|
|
6187
2075
|
exports.SignInSelect = SignInSelect;
|
|
6188
2076
|
exports.SignInTextField = SignInTextField;
|
|
6189
|
-
exports.SmallIconButton = SmallIconButton;
|
|
6190
|
-
exports.THREAD_HEADER_ACTIONS_CLASS = THREAD_HEADER_ACTIONS_CLASS;
|
|
6191
|
-
exports.THREAD_HEADER_CLASS = THREAD_HEADER_CLASS;
|
|
6192
|
-
exports.THREAD_HEADER_ICON_CLASS = THREAD_HEADER_ICON_CLASS;
|
|
6193
|
-
exports.THREAD_HEADER_PILL_CLASS = THREAD_HEADER_PILL_CLASS;
|
|
6194
|
-
exports.THREAD_PANEL_CLASS = THREAD_PANEL_CLASS;
|
|
6195
|
-
exports.THREAD_SCROLL_TO_BOTTOM_CLASS = THREAD_SCROLL_TO_BOTTOM_CLASS;
|
|
6196
|
-
exports.TextShimmerLoader = TextShimmerLoader;
|
|
6197
|
-
exports.ThreadRunningIndicator = ThreadRunningIndicator;
|
|
6198
2077
|
exports.TiptapComposer = TiptapComposer;
|
|
6199
|
-
exports.UserMessage = UserMessage;
|
|
6200
|
-
exports.assetTypeToIcon = assetTypeToIcon;
|
|
6201
|
-
exports.assetTypeToThumb = assetTypeToThumb;
|
|
6202
2078
|
exports.buildRootMenuItems = buildRootMenuItems;
|
|
6203
|
-
exports.configureAssetIconBasePath = configureAssetIconBasePath;
|
|
6204
|
-
exports.createAssistantMessage = createAssistantMessage;
|
|
6205
|
-
exports.createOlympusAssetUrl = createOlympusAssetUrl;
|
|
6206
|
-
exports.fetchGraphQL = fetchGraphQL;
|
|
6207
2079
|
exports.makeMentionUrl = makeMentionUrl;
|
|
6208
|
-
exports.normalizeAthenaMentionHtml = normalizeAthenaMentionHtml;
|
|
6209
2080
|
exports.parseMentionAnchorAttributes = parseMentionAnchorAttributes;
|
|
6210
|
-
exports.parseMentionUrl = parseMentionUrl;
|
|
6211
|
-
exports.parseMentionsInText = parseMentionsInText;
|
|
6212
2081
|
exports.plainTextToTiptapContent = plainTextToTiptapContent;
|
|
6213
|
-
exports.resolveComposerAction = resolveComposerAction;
|
|
6214
|
-
exports.useMentionAuth = useMentionAuth;
|
|
6215
2082
|
exports.useMentionSuggestions = useMentionSuggestions;
|
|
6216
2083
|
exports.webpageMentionFingerprint = webpageMentionFingerprint;
|
|
6217
2084
|
//# sourceMappingURL=chat-ui.cjs.map
|