@vizel/core 0.0.1-alpha.5 → 1.0.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/components.css +1 -1
- package/dist/components.css.map +1 -1
- package/dist/index.d.ts +230 -15
- package/dist/index.js +78 -75
- package/dist/index10.js +1 -1
- package/dist/index11.js +4 -4
- package/dist/index14.js +1 -1
- package/dist/index15.js +134 -127
- package/dist/index17.js +2 -2
- package/dist/index18.js +1 -1
- package/dist/index19.js +86 -86
- package/dist/index20.js +2 -2
- package/dist/index21.js +2 -2
- package/dist/index22.js +16 -13
- package/dist/index24.js +164 -11
- package/dist/index25.js +12 -53
- package/dist/index26.js +49 -136
- package/dist/index27.js +132 -59
- package/dist/index28.js +66 -32
- package/dist/index29.js +35 -21
- package/dist/index3.js +91 -90
- package/dist/index30.js +23 -9
- package/dist/index31.js +9 -147
- package/dist/index32.js +138 -256
- package/dist/index33.js +258 -85
- package/dist/index34.js +84 -55
- package/dist/index35.js +64 -4
- package/dist/index36.js +4 -123
- package/dist/index37.js +111 -315
- package/dist/index38.js +321 -481
- package/dist/index39.js +12 -47
- package/dist/index4.js +1 -1
- package/dist/index40.js +463 -655
- package/dist/index41.js +48 -4
- package/dist/index42.js +694 -4
- package/dist/index43.js +4 -238
- package/dist/index44.js +4 -82
- package/dist/index45.js +237 -16
- package/dist/index46.js +81 -57
- package/dist/index47.js +17 -15
- package/dist/index48.js +57 -285
- package/dist/index49.js +15 -202
- package/dist/index5.js +78 -68
- package/dist/index50.js +281 -1497
- package/dist/index51.js +202 -5
- package/dist/index52.js +1408 -1467
- package/dist/index53.js +5 -723
- package/dist/index54.js +1109 -81
- package/dist/index55.js +703 -226
- package/dist/index56.js +84 -3
- package/dist/index57.js +219 -1205
- package/dist/index58.js +3 -734
- package/dist/index59.js +1232 -21
- package/dist/index6.js +1 -1
- package/dist/index60.js +734 -10
- package/dist/index61.js +21 -7
- package/dist/index62.js +10 -8
- package/dist/index63.js +6 -13
- package/dist/index64.js +7 -18
- package/dist/index65.js +12 -23
- package/dist/index66.js +17 -53
- package/dist/index67.js +23 -1059
- package/dist/index68.js +54 -90
- package/dist/index69.js +1061 -98
- package/dist/index7.js +108 -96
- package/dist/index70.js +98 -4
- package/dist/index71.js +93 -0
- package/dist/index72.js +6 -0
- package/dist/index8.js +1 -1
- package/dist/index9.js +75 -65
- package/dist/mathematics.css +1 -0
- package/dist/mathematics.css.map +1 -0
- package/dist/styles.css +1 -1
- package/dist/styles.css.map +1 -1
- package/package.json +90 -52
package/dist/index42.js
CHANGED
|
@@ -1,6 +1,696 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { Extension as H, commands as y, flattenExtensions as z, getExtensionField as C, generateJSON as L } from "@tiptap/core";
|
|
2
|
+
import { marked as P } from "./index54.js";
|
|
3
|
+
function _(e, n) {
|
|
4
|
+
const s = n.split(`
|
|
5
|
+
`).flatMap((r) => [r, ""]).map((r) => `${e}${r}`).join(`
|
|
6
|
+
`);
|
|
7
|
+
return s.slice(0, s.length - 1);
|
|
8
|
+
}
|
|
9
|
+
function O(e, n) {
|
|
10
|
+
const t = [];
|
|
11
|
+
return Array.from(e.keys()).forEach((s) => {
|
|
12
|
+
(!n || !n.marks || !n.marks.map((r) => r.type).includes(s)) && t.push(s);
|
|
13
|
+
}), t;
|
|
14
|
+
}
|
|
15
|
+
function F(e, n) {
|
|
16
|
+
const t = [];
|
|
17
|
+
return Array.from(n.entries()).forEach(([s, r]) => {
|
|
18
|
+
e.has(s) || t.push({ type: s, mark: r });
|
|
19
|
+
}), t;
|
|
20
|
+
}
|
|
21
|
+
function $(e, n, t, s) {
|
|
22
|
+
const r = !t, i = t && t.type === "text" && (!t.marks || t.marks.length === 0), o = t && t.type === "text" && t.marks && !s(n, new Map(t.marks.map((d) => [d.type, d]))), l = [];
|
|
23
|
+
if (r || i || o)
|
|
24
|
+
if (t && t.type === "text" && t.marks) {
|
|
25
|
+
const d = new Map(t.marks.map((a) => [a.type, a]));
|
|
26
|
+
Array.from(e.keys()).forEach((a) => {
|
|
27
|
+
d.has(a) || l.push(a);
|
|
28
|
+
});
|
|
29
|
+
} else (r || i) && l.push(...Array.from(e.keys()));
|
|
30
|
+
return l;
|
|
31
|
+
}
|
|
32
|
+
function N(e, n) {
|
|
33
|
+
let t = "";
|
|
34
|
+
return Array.from(e.keys()).reverse().forEach((s) => {
|
|
35
|
+
const r = e.get(s), i = n(s, r);
|
|
36
|
+
i && (t = i + t);
|
|
37
|
+
}), e.clear(), t;
|
|
38
|
+
}
|
|
39
|
+
function S(e, n, t) {
|
|
40
|
+
let s = "";
|
|
41
|
+
return Array.from(e.entries()).forEach(([r, i]) => {
|
|
42
|
+
const o = t(r, i);
|
|
43
|
+
o && (s += o), n.set(r, i);
|
|
44
|
+
}), s;
|
|
45
|
+
}
|
|
46
|
+
function R(e) {
|
|
47
|
+
const t = (e.raw || e.text || "").match(/^(\s*)[-+*]\s+\[([ xX])\]\s+/);
|
|
48
|
+
return t ? { isTask: !0, checked: t[2].toLowerCase() === "x", indentLevel: t[1].length } : { isTask: !1, indentLevel: 0 };
|
|
49
|
+
}
|
|
50
|
+
function E(e, n) {
|
|
51
|
+
return typeof e != "string" ? "json" : n;
|
|
52
|
+
}
|
|
53
|
+
var j = class {
|
|
54
|
+
/**
|
|
55
|
+
* Create a MarkdownManager.
|
|
56
|
+
* @param options.marked Optional marked instance to use (injected).
|
|
57
|
+
* @param options.markedOptions Optional options to pass to marked.setOptions
|
|
58
|
+
* @param options.indentation Indentation settings (style and size).
|
|
59
|
+
* @param options.extensions An array of Tiptap extensions to register for markdown parsing and rendering.
|
|
60
|
+
*/
|
|
61
|
+
constructor(e) {
|
|
62
|
+
this.baseExtensions = [], this.extensions = [], this.lastParseResult = null;
|
|
63
|
+
var n, t, s, r, i;
|
|
64
|
+
this.markedInstance = (n = e?.marked) != null ? n : P, this.lexer = new this.markedInstance.Lexer(), this.indentStyle = (s = (t = e?.indentation) == null ? void 0 : t.style) != null ? s : "space", this.indentSize = (i = (r = e?.indentation) == null ? void 0 : r.size) != null ? i : 2, this.baseExtensions = e?.extensions || [], e?.markedOptions && typeof this.markedInstance.setOptions == "function" && this.markedInstance.setOptions(e.markedOptions), this.registry = /* @__PURE__ */ new Map(), this.nodeTypeRegistry = /* @__PURE__ */ new Map(), e?.extensions && (this.baseExtensions = e.extensions, z(e.extensions).forEach((l) => this.registerExtension(l, !1))), this.lexer = new this.markedInstance.Lexer();
|
|
65
|
+
}
|
|
66
|
+
/** Returns the underlying marked instance. */
|
|
67
|
+
get instance() {
|
|
68
|
+
return this.markedInstance;
|
|
69
|
+
}
|
|
70
|
+
/** Returns the correct indentCharacter (space or tab) */
|
|
71
|
+
get indentCharacter() {
|
|
72
|
+
return this.indentStyle === "space" ? " " : " ";
|
|
73
|
+
}
|
|
74
|
+
/** Returns the correct indentString repeated X times */
|
|
75
|
+
get indentString() {
|
|
76
|
+
return this.indentCharacter.repeat(this.indentSize);
|
|
77
|
+
}
|
|
78
|
+
/** Helper to quickly check whether a marked instance is available. */
|
|
79
|
+
hasMarked() {
|
|
80
|
+
return !!this.markedInstance;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Register a Tiptap extension (Node/Mark/Extension). This will read
|
|
84
|
+
* `markdownName`, `parseMarkdown`, `renderMarkdown` and `priority` from the
|
|
85
|
+
* extension config (using the same resolution used across the codebase).
|
|
86
|
+
*/
|
|
87
|
+
registerExtension(e, n = !0) {
|
|
88
|
+
var t, s;
|
|
89
|
+
this.extensions.push(e);
|
|
90
|
+
const r = e.name, i = C(e, "markdownTokenName") || r, o = C(e, "parseMarkdown"), l = C(e, "renderMarkdown"), d = C(e, "markdownTokenizer"), a = (t = C(e, "markdownOptions")) != null ? t : null, c = (s = a?.indentsContent) != null ? s : !1, p = {
|
|
91
|
+
tokenName: i,
|
|
92
|
+
nodeName: r,
|
|
93
|
+
parseMarkdown: o,
|
|
94
|
+
renderMarkdown: l,
|
|
95
|
+
isIndenting: c,
|
|
96
|
+
tokenizer: d
|
|
97
|
+
};
|
|
98
|
+
if (i && o) {
|
|
99
|
+
const u = this.registry.get(i) || [];
|
|
100
|
+
u.push(p), this.registry.set(i, u);
|
|
101
|
+
}
|
|
102
|
+
if (l) {
|
|
103
|
+
const u = this.nodeTypeRegistry.get(r) || [];
|
|
104
|
+
u.push(p), this.nodeTypeRegistry.set(r, u);
|
|
105
|
+
}
|
|
106
|
+
d && this.hasMarked() && (this.registerTokenizer(d), n && (this.lexer = new this.markedInstance.Lexer()));
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Register a custom tokenizer with marked.js for parsing non-standard markdown syntax.
|
|
110
|
+
*/
|
|
111
|
+
registerTokenizer(e) {
|
|
112
|
+
if (!this.hasMarked())
|
|
113
|
+
return;
|
|
114
|
+
const { name: n, start: t, level: s = "inline", tokenize: r } = e, l = {
|
|
115
|
+
inlineTokens: (c) => this.lexer.inlineTokens(c),
|
|
116
|
+
blockTokens: (c) => this.lexer.blockTokens(c)
|
|
117
|
+
};
|
|
118
|
+
let d;
|
|
119
|
+
t ? d = typeof t == "function" ? t : (c) => c.indexOf(t) : d = (c) => {
|
|
120
|
+
const p = r(c, [], l);
|
|
121
|
+
return p && p.raw ? c.indexOf(p.raw) : -1;
|
|
122
|
+
};
|
|
123
|
+
const a = {
|
|
124
|
+
name: n,
|
|
125
|
+
level: s,
|
|
126
|
+
start: d,
|
|
127
|
+
tokenizer: (c, p) => {
|
|
128
|
+
const u = r(c, p, l);
|
|
129
|
+
if (u && u.type)
|
|
130
|
+
return {
|
|
131
|
+
...u,
|
|
132
|
+
type: u.type || n,
|
|
133
|
+
raw: u.raw || "",
|
|
134
|
+
tokens: u.tokens || []
|
|
135
|
+
};
|
|
136
|
+
},
|
|
137
|
+
childTokens: []
|
|
138
|
+
};
|
|
139
|
+
this.markedInstance.use({
|
|
140
|
+
extensions: [a]
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
/** Get registered handlers for a token type and try each until one succeeds. */
|
|
144
|
+
getHandlersForToken(e) {
|
|
145
|
+
try {
|
|
146
|
+
return this.registry.get(e) || [];
|
|
147
|
+
} catch {
|
|
148
|
+
return [];
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/** Get the first handler for a token type (for backwards compatibility). */
|
|
152
|
+
getHandlerForToken(e) {
|
|
153
|
+
const n = this.getHandlersForToken(e);
|
|
154
|
+
if (n.length > 0)
|
|
155
|
+
return n[0];
|
|
156
|
+
const t = this.getHandlersForNodeType(e);
|
|
157
|
+
return t.length > 0 ? t[0] : void 0;
|
|
158
|
+
}
|
|
159
|
+
/** Get registered handlers for a node type (for rendering). */
|
|
160
|
+
getHandlersForNodeType(e) {
|
|
161
|
+
try {
|
|
162
|
+
return this.nodeTypeRegistry.get(e) || [];
|
|
163
|
+
} catch {
|
|
164
|
+
return [];
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Serialize a ProseMirror-like JSON document (or node array) to a Markdown string
|
|
169
|
+
* using registered renderers and fallback renderers.
|
|
170
|
+
*/
|
|
171
|
+
serialize(e) {
|
|
172
|
+
return e ? Array.isArray(e) ? this.renderNodes(e, e) : this.renderNodes(e, e) : "";
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Parse markdown string into Tiptap JSON document using registered extension handlers.
|
|
176
|
+
*/
|
|
177
|
+
parse(e) {
|
|
178
|
+
if (!this.hasMarked())
|
|
179
|
+
throw new Error("No marked instance available for parsing");
|
|
180
|
+
const n = this.markedInstance.lexer(e);
|
|
181
|
+
return {
|
|
182
|
+
type: "doc",
|
|
183
|
+
content: this.parseTokens(n)
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Convert an array of marked tokens into Tiptap JSON nodes using registered extension handlers.
|
|
188
|
+
*/
|
|
189
|
+
parseTokens(e) {
|
|
190
|
+
return e.map((n) => this.parseToken(n)).filter((n) => n !== null).flatMap((n) => Array.isArray(n) ? n : [n]);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Parse a single token into Tiptap JSON using the appropriate registered handler.
|
|
194
|
+
*/
|
|
195
|
+
parseToken(e) {
|
|
196
|
+
if (!e.type)
|
|
197
|
+
return null;
|
|
198
|
+
if (e.type === "list")
|
|
199
|
+
return this.parseListToken(e);
|
|
200
|
+
const n = this.getHandlersForToken(e.type), t = this.createParseHelpers();
|
|
201
|
+
if (n.find((r) => {
|
|
202
|
+
if (!r.parseMarkdown)
|
|
203
|
+
return !1;
|
|
204
|
+
const i = r.parseMarkdown(e, t), o = this.normalizeParseResult(i);
|
|
205
|
+
return o && (!Array.isArray(o) || o.length > 0) ? (this.lastParseResult = o, !0) : !1;
|
|
206
|
+
}) && this.lastParseResult) {
|
|
207
|
+
const r = this.lastParseResult;
|
|
208
|
+
return this.lastParseResult = null, r;
|
|
209
|
+
}
|
|
210
|
+
return this.parseFallbackToken(e);
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Parse a list token, handling mixed bullet and task list items by splitting them into separate lists.
|
|
214
|
+
* This ensures that consecutive task items and bullet items are grouped and parsed as separate list nodes.
|
|
215
|
+
*
|
|
216
|
+
* @param token The list token to parse
|
|
217
|
+
* @returns Array of parsed list nodes, or null if parsing fails
|
|
218
|
+
*/
|
|
219
|
+
parseListToken(e) {
|
|
220
|
+
if (!e.items || e.items.length === 0)
|
|
221
|
+
return this.parseTokenWithHandlers(e);
|
|
222
|
+
const n = e.items.some((l) => R(l).isTask), t = e.items.some((l) => !R(l).isTask);
|
|
223
|
+
if (!n || !t || this.getHandlersForToken("taskList").length === 0)
|
|
224
|
+
return this.parseTokenWithHandlers(e);
|
|
225
|
+
const s = [];
|
|
226
|
+
let r = [], i = null;
|
|
227
|
+
for (let l = 0; l < e.items.length; l += 1) {
|
|
228
|
+
const d = e.items[l], { isTask: a, checked: c, indentLevel: p } = R(d);
|
|
229
|
+
let u = d;
|
|
230
|
+
if (a) {
|
|
231
|
+
const m = (d.raw || d.text || "").split(`
|
|
232
|
+
`), g = m[0].match(/^\s*[-+*]\s+\[([ xX])\]\s+(.*)$/), h = g ? g[2] : "";
|
|
233
|
+
let k = [];
|
|
234
|
+
if (m.length > 1 && m.slice(1).join(`
|
|
235
|
+
`).trim()) {
|
|
236
|
+
const T = m.slice(1), v = T.filter((A) => A.trim());
|
|
237
|
+
if (v.length > 0) {
|
|
238
|
+
const A = Math.min(...v.map((x) => x.length - x.trimStart().length)), b = T.map((x) => x.trim() ? x.slice(A) : "").join(`
|
|
239
|
+
`).trim();
|
|
240
|
+
b && (k = this.markedInstance.lexer(`${b}
|
|
241
|
+
`));
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
u = {
|
|
245
|
+
type: "taskItem",
|
|
246
|
+
raw: "",
|
|
247
|
+
mainContent: h,
|
|
248
|
+
indentLevel: p,
|
|
249
|
+
checked: c ?? !1,
|
|
250
|
+
text: h,
|
|
251
|
+
tokens: this.lexer.inlineTokens(h),
|
|
252
|
+
nestedTokens: k
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
const w = a ? "taskList" : "list";
|
|
256
|
+
i !== w ? (r.length > 0 && s.push({ type: i, items: r }), r = [u], i = w) : r.push(u);
|
|
257
|
+
}
|
|
258
|
+
r.length > 0 && s.push({ type: i, items: r });
|
|
259
|
+
const o = [];
|
|
260
|
+
for (let l = 0; l < s.length; l += 1) {
|
|
261
|
+
const d = s[l], a = { ...e, type: d.type, items: d.items }, c = this.parseToken(a);
|
|
262
|
+
c && (Array.isArray(c) ? o.push(...c) : o.push(c));
|
|
263
|
+
}
|
|
264
|
+
return o.length > 0 ? o : null;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Parse a token using registered handlers (extracted for reuse).
|
|
268
|
+
*/
|
|
269
|
+
parseTokenWithHandlers(e) {
|
|
270
|
+
if (!e.type)
|
|
271
|
+
return null;
|
|
272
|
+
const n = this.getHandlersForToken(e.type), t = this.createParseHelpers();
|
|
273
|
+
if (n.find((r) => {
|
|
274
|
+
if (!r.parseMarkdown)
|
|
275
|
+
return !1;
|
|
276
|
+
const i = r.parseMarkdown(e, t), o = this.normalizeParseResult(i);
|
|
277
|
+
return o && (!Array.isArray(o) || o.length > 0) ? (this.lastParseResult = o, !0) : !1;
|
|
278
|
+
}) && this.lastParseResult) {
|
|
279
|
+
const r = this.lastParseResult;
|
|
280
|
+
return this.lastParseResult = null, r;
|
|
281
|
+
}
|
|
282
|
+
return this.parseFallbackToken(e);
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Creates helper functions for parsing markdown tokens.
|
|
286
|
+
* @returns An object containing helper functions for parsing.
|
|
287
|
+
*/
|
|
288
|
+
createParseHelpers() {
|
|
289
|
+
return {
|
|
290
|
+
parseInline: (e) => this.parseInlineTokens(e),
|
|
291
|
+
parseChildren: (e) => this.parseTokens(e),
|
|
292
|
+
createTextNode: (e, n) => ({
|
|
293
|
+
type: "text",
|
|
294
|
+
text: e,
|
|
295
|
+
marks: n || void 0
|
|
296
|
+
}),
|
|
297
|
+
createNode: (e, n, t) => {
|
|
298
|
+
const s = {
|
|
299
|
+
type: e,
|
|
300
|
+
attrs: n || void 0,
|
|
301
|
+
content: t || void 0
|
|
302
|
+
};
|
|
303
|
+
return (!n || Object.keys(n).length === 0) && delete s.attrs, s;
|
|
304
|
+
},
|
|
305
|
+
applyMark: (e, n, t) => ({
|
|
306
|
+
mark: e,
|
|
307
|
+
content: n,
|
|
308
|
+
attrs: t && Object.keys(t).length > 0 ? t : void 0
|
|
309
|
+
})
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Escape special regex characters in a string.
|
|
314
|
+
*/
|
|
315
|
+
escapeRegex(e) {
|
|
316
|
+
return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Parse inline tokens (bold, italic, links, etc.) into text nodes with marks.
|
|
320
|
+
* This is the complex part that handles mark nesting and boundaries.
|
|
321
|
+
*/
|
|
322
|
+
parseInlineTokens(e) {
|
|
323
|
+
var n, t, s, r;
|
|
324
|
+
const i = [];
|
|
325
|
+
for (let o = 0; o < e.length; o += 1) {
|
|
326
|
+
const l = e[o];
|
|
327
|
+
if (l.type === "text")
|
|
328
|
+
i.push({
|
|
329
|
+
type: "text",
|
|
330
|
+
text: l.text || ""
|
|
331
|
+
});
|
|
332
|
+
else if (l.type === "html") {
|
|
333
|
+
const d = ((t = (n = l.raw) != null ? n : l.text) != null ? t : "").toString(), a = /^<\/[\s]*[\w-]+/i.test(d), c = d.match(/^<[\s]*([\w-]+)(\s|>|\/|$)/i);
|
|
334
|
+
if (!a && c && !/\/>$/.test(d)) {
|
|
335
|
+
const u = c[1], w = this.escapeRegex(u), M = new RegExp(`^<\\/\\s*${w}\\b`, "i");
|
|
336
|
+
let m = -1;
|
|
337
|
+
const g = [d];
|
|
338
|
+
for (let h = o + 1; h < e.length; h += 1) {
|
|
339
|
+
const k = e[h], f = ((r = (s = k.raw) != null ? s : k.text) != null ? r : "").toString();
|
|
340
|
+
if (g.push(f), k.type === "html" && M.test(f)) {
|
|
341
|
+
m = h;
|
|
342
|
+
break;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
if (m !== -1) {
|
|
346
|
+
const h = g.join(""), k = {
|
|
347
|
+
type: "html",
|
|
348
|
+
raw: h,
|
|
349
|
+
text: h,
|
|
350
|
+
block: !1
|
|
351
|
+
}, f = this.parseHTMLToken(k);
|
|
352
|
+
if (f) {
|
|
353
|
+
const T = this.normalizeParseResult(f);
|
|
354
|
+
Array.isArray(T) ? i.push(...T) : T && i.push(T);
|
|
355
|
+
}
|
|
356
|
+
o = m;
|
|
357
|
+
continue;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
const p = this.parseHTMLToken(l);
|
|
361
|
+
if (p) {
|
|
362
|
+
const u = this.normalizeParseResult(p);
|
|
363
|
+
Array.isArray(u) ? i.push(...u) : u && i.push(u);
|
|
364
|
+
}
|
|
365
|
+
} else if (l.type) {
|
|
366
|
+
const d = this.getHandlerForToken(l.type);
|
|
367
|
+
if (d && d.parseMarkdown) {
|
|
368
|
+
const a = this.createParseHelpers(), c = d.parseMarkdown(l, a);
|
|
369
|
+
if (this.isMarkResult(c)) {
|
|
370
|
+
const p = this.applyMarkToContent(c.mark, c.content, c.attrs);
|
|
371
|
+
i.push(...p);
|
|
372
|
+
} else {
|
|
373
|
+
const p = this.normalizeParseResult(c);
|
|
374
|
+
Array.isArray(p) ? i.push(...p) : p && i.push(p);
|
|
375
|
+
}
|
|
376
|
+
} else l.tokens && i.push(...this.parseInlineTokens(l.tokens));
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
return i;
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Apply a mark to content nodes.
|
|
383
|
+
*/
|
|
384
|
+
applyMarkToContent(e, n, t) {
|
|
385
|
+
return n.map((s) => {
|
|
386
|
+
if (s.type === "text") {
|
|
387
|
+
const r = s.marks || [], i = t ? { type: e, attrs: t } : { type: e };
|
|
388
|
+
return {
|
|
389
|
+
...s,
|
|
390
|
+
marks: [...r, i]
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
return {
|
|
394
|
+
...s,
|
|
395
|
+
content: s.content ? this.applyMarkToContent(e, s.content, t) : void 0
|
|
396
|
+
};
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Check if a parse result represents a mark to be applied.
|
|
401
|
+
*/
|
|
402
|
+
isMarkResult(e) {
|
|
403
|
+
return e && typeof e == "object" && "mark" in e;
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Normalize parse results to ensure they're valid JSONContent.
|
|
407
|
+
*/
|
|
408
|
+
normalizeParseResult(e) {
|
|
409
|
+
return e ? this.isMarkResult(e) ? e.content : e : null;
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Fallback parsing for common tokens when no specific handler is registered.
|
|
413
|
+
*/
|
|
414
|
+
parseFallbackToken(e) {
|
|
415
|
+
switch (e.type) {
|
|
416
|
+
case "paragraph":
|
|
417
|
+
return {
|
|
418
|
+
type: "paragraph",
|
|
419
|
+
content: e.tokens ? this.parseInlineTokens(e.tokens) : []
|
|
420
|
+
};
|
|
421
|
+
case "heading":
|
|
422
|
+
return {
|
|
423
|
+
type: "heading",
|
|
424
|
+
attrs: { level: e.depth || 1 },
|
|
425
|
+
content: e.tokens ? this.parseInlineTokens(e.tokens) : []
|
|
426
|
+
};
|
|
427
|
+
case "text":
|
|
428
|
+
return {
|
|
429
|
+
type: "text",
|
|
430
|
+
text: e.text || ""
|
|
431
|
+
};
|
|
432
|
+
case "html":
|
|
433
|
+
return this.parseHTMLToken(e);
|
|
434
|
+
case "space":
|
|
435
|
+
return null;
|
|
436
|
+
default:
|
|
437
|
+
return e.tokens ? this.parseTokens(e.tokens) : null;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* Parse HTML tokens using extensions' parseHTML methods.
|
|
442
|
+
* This allows HTML within markdown to be parsed according to extension rules.
|
|
443
|
+
*/
|
|
444
|
+
parseHTMLToken(e) {
|
|
445
|
+
const n = e.text || e.raw || "";
|
|
446
|
+
if (!n.trim())
|
|
447
|
+
return null;
|
|
448
|
+
if (typeof window > "u")
|
|
449
|
+
return e.block ? {
|
|
450
|
+
type: "paragraph",
|
|
451
|
+
content: [
|
|
452
|
+
{
|
|
453
|
+
type: "text",
|
|
454
|
+
text: n
|
|
455
|
+
}
|
|
456
|
+
]
|
|
457
|
+
} : {
|
|
458
|
+
type: "text",
|
|
459
|
+
text: n
|
|
460
|
+
};
|
|
461
|
+
try {
|
|
462
|
+
const t = L(n, this.baseExtensions);
|
|
463
|
+
return t.type === "doc" && t.content ? e.block ? t.content : t.content.length === 1 && t.content[0].type === "paragraph" && t.content[0].content ? t.content[0].content : t.content : t;
|
|
464
|
+
} catch (t) {
|
|
465
|
+
throw new Error(`Failed to parse HTML in markdown: ${t}`);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
renderNodeToMarkdown(e, n, t = 0, s = 0) {
|
|
469
|
+
var r;
|
|
470
|
+
if (e.type === "text")
|
|
471
|
+
return e.text || "";
|
|
472
|
+
if (!e.type)
|
|
473
|
+
return "";
|
|
474
|
+
const i = this.getHandlerForToken(e.type);
|
|
475
|
+
if (!i)
|
|
476
|
+
return "";
|
|
477
|
+
const o = {
|
|
478
|
+
renderChildren: (a, c) => {
|
|
479
|
+
const p = i.isIndenting ? s + 1 : s;
|
|
480
|
+
return !Array.isArray(a) && a.content ? this.renderNodes(a.content, e, c || "", t, p) : this.renderNodes(a, e, c || "", t, p);
|
|
481
|
+
},
|
|
482
|
+
indent: (a) => this.indentString + a,
|
|
483
|
+
wrapInBlock: _
|
|
484
|
+
}, l = {
|
|
485
|
+
index: t,
|
|
486
|
+
level: s,
|
|
487
|
+
parentType: n?.type,
|
|
488
|
+
meta: {
|
|
489
|
+
parentAttrs: n?.attrs
|
|
490
|
+
}
|
|
491
|
+
};
|
|
492
|
+
return ((r = i.renderMarkdown) == null ? void 0 : r.call(i, e, o, l)) || "";
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* Render a node or an array of nodes. Parent type controls how children
|
|
496
|
+
* are joined (which determines newline insertion between children).
|
|
497
|
+
*/
|
|
498
|
+
renderNodes(e, n, t = "", s = 0, r = 0) {
|
|
499
|
+
return Array.isArray(e) ? this.renderNodesWithMarkBoundaries(e, n, t, r) : e.type ? this.renderNodeToMarkdown(e, n, s, r) : "";
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* Render an array of nodes while properly tracking mark boundaries.
|
|
503
|
+
* This handles cases where marks span across multiple text nodes.
|
|
504
|
+
*/
|
|
505
|
+
renderNodesWithMarkBoundaries(e, n, t = "", s = 0) {
|
|
506
|
+
const r = [], i = /* @__PURE__ */ new Map();
|
|
507
|
+
return e.forEach((o, l) => {
|
|
508
|
+
const d = l < e.length - 1 ? e[l + 1] : null;
|
|
509
|
+
if (o.type)
|
|
510
|
+
if (o.type === "text") {
|
|
511
|
+
let a = o.text || "";
|
|
512
|
+
const c = new Map((o.marks || []).map((h) => [h.type, h])), p = F(i, c), u = O(c, d);
|
|
513
|
+
let w = "";
|
|
514
|
+
if (u.length > 0) {
|
|
515
|
+
const h = a.match(/(\s+)$/);
|
|
516
|
+
h && (w = h[1], a = a.slice(0, -w.length));
|
|
517
|
+
}
|
|
518
|
+
u.forEach((h) => {
|
|
519
|
+
const k = c.get(h), f = this.getMarkClosing(h, k);
|
|
520
|
+
f && (a += f), i.has(h) && i.delete(h);
|
|
521
|
+
});
|
|
522
|
+
let M = "";
|
|
523
|
+
if (p.length > 0) {
|
|
524
|
+
const h = a.match(/^(\s+)/);
|
|
525
|
+
h && (M = h[1], a = a.slice(M.length));
|
|
526
|
+
}
|
|
527
|
+
p.forEach(({ type: h, mark: k }) => {
|
|
528
|
+
const f = this.getMarkOpening(h, k);
|
|
529
|
+
f && (a = f + a), u.includes(h) || i.set(h, k);
|
|
530
|
+
}), a = M + a;
|
|
531
|
+
const m = $(
|
|
532
|
+
i,
|
|
533
|
+
c,
|
|
534
|
+
d,
|
|
535
|
+
this.markSetsEqual.bind(this)
|
|
536
|
+
);
|
|
537
|
+
let g = "";
|
|
538
|
+
if (m.length > 0) {
|
|
539
|
+
const h = a.match(/(\s+)$/);
|
|
540
|
+
h && (g = h[1], a = a.slice(0, -g.length));
|
|
541
|
+
}
|
|
542
|
+
m.forEach((h) => {
|
|
543
|
+
const k = i.get(h), f = this.getMarkClosing(h, k);
|
|
544
|
+
f && (a += f), i.delete(h);
|
|
545
|
+
}), a += g, a += w, r.push(a);
|
|
546
|
+
} else {
|
|
547
|
+
const a = new Map(i), c = N(i, this.getMarkClosing.bind(this)), p = this.renderNodeToMarkdown(o, n, l, s), u = o.type === "hardBreak" ? "" : S(a, i, this.getMarkOpening.bind(this));
|
|
548
|
+
r.push(c + p + u);
|
|
549
|
+
}
|
|
550
|
+
}), r.join(t);
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* Get the opening markdown syntax for a mark type.
|
|
554
|
+
*/
|
|
555
|
+
getMarkOpening(e, n) {
|
|
556
|
+
const t = this.getHandlersForNodeType(e), s = t.length > 0 ? t[0] : void 0;
|
|
557
|
+
if (!s || !s.renderMarkdown)
|
|
558
|
+
return "";
|
|
559
|
+
const r = "__TIPTAP_MARKDOWN_PLACEHOLDER__", i = {
|
|
560
|
+
type: e,
|
|
561
|
+
attrs: n.attrs || {},
|
|
562
|
+
content: [{ type: "text", text: r }]
|
|
563
|
+
};
|
|
564
|
+
try {
|
|
565
|
+
const o = s.renderMarkdown(
|
|
566
|
+
i,
|
|
567
|
+
{
|
|
568
|
+
renderChildren: () => r,
|
|
569
|
+
indent: (d) => d,
|
|
570
|
+
wrapInBlock: (d, a) => d + a
|
|
571
|
+
},
|
|
572
|
+
{ index: 0, level: 0, parentType: "text", meta: {} }
|
|
573
|
+
), l = o.indexOf(r);
|
|
574
|
+
return l >= 0 ? o.substring(0, l) : "";
|
|
575
|
+
} catch (o) {
|
|
576
|
+
throw new Error(`Failed to get mark opening for ${e}: ${o}`);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
580
|
+
* Get the closing markdown syntax for a mark type.
|
|
581
|
+
*/
|
|
582
|
+
getMarkClosing(e, n) {
|
|
583
|
+
const t = this.getHandlersForNodeType(e), s = t.length > 0 ? t[0] : void 0;
|
|
584
|
+
if (!s || !s.renderMarkdown)
|
|
585
|
+
return "";
|
|
586
|
+
const r = "__TIPTAP_MARKDOWN_PLACEHOLDER__", i = {
|
|
587
|
+
type: e,
|
|
588
|
+
attrs: n.attrs || {},
|
|
589
|
+
content: [{ type: "text", text: r }]
|
|
590
|
+
};
|
|
591
|
+
try {
|
|
592
|
+
const o = s.renderMarkdown(
|
|
593
|
+
i,
|
|
594
|
+
{
|
|
595
|
+
renderChildren: () => r,
|
|
596
|
+
indent: (a) => a,
|
|
597
|
+
wrapInBlock: (a, c) => a + c
|
|
598
|
+
},
|
|
599
|
+
{ index: 0, level: 0, parentType: "text", meta: {} }
|
|
600
|
+
), l = o.indexOf(r), d = l + r.length;
|
|
601
|
+
return l >= 0 ? o.substring(d) : "";
|
|
602
|
+
} catch (o) {
|
|
603
|
+
throw new Error(`Failed to get mark closing for ${e}: ${o}`);
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
/**
|
|
607
|
+
* Check if two mark sets are equal.
|
|
608
|
+
*/
|
|
609
|
+
markSetsEqual(e, n) {
|
|
610
|
+
return e.size !== n.size ? !1 : Array.from(e.keys()).every((t) => n.has(t));
|
|
611
|
+
}
|
|
612
|
+
}, I = j, q = H.create({
|
|
613
|
+
name: "markdown",
|
|
614
|
+
addOptions() {
|
|
615
|
+
return {
|
|
616
|
+
indentation: { style: "space", size: 2 },
|
|
617
|
+
marked: void 0,
|
|
618
|
+
markedOptions: {}
|
|
619
|
+
};
|
|
620
|
+
},
|
|
621
|
+
addCommands() {
|
|
622
|
+
return {
|
|
623
|
+
setContent: (e, n) => {
|
|
624
|
+
if (!n?.contentType)
|
|
625
|
+
return y.setContent(e, n);
|
|
626
|
+
if (E(e, n?.contentType) !== "markdown" || !this.editor.markdown)
|
|
627
|
+
return y.setContent(e, n);
|
|
628
|
+
const s = this.editor.markdown.parse(e);
|
|
629
|
+
return y.setContent(s, n);
|
|
630
|
+
},
|
|
631
|
+
insertContent: (e, n) => {
|
|
632
|
+
if (!n?.contentType)
|
|
633
|
+
return y.insertContent(e, n);
|
|
634
|
+
if (E(e, n?.contentType) !== "markdown" || !this.editor.markdown)
|
|
635
|
+
return y.insertContent(e, n);
|
|
636
|
+
const s = this.editor.markdown.parse(e);
|
|
637
|
+
return y.insertContent(s, n);
|
|
638
|
+
},
|
|
639
|
+
insertContentAt: (e, n, t) => {
|
|
640
|
+
if (!t?.contentType)
|
|
641
|
+
return y.insertContentAt(e, n, t);
|
|
642
|
+
if (E(n, t?.contentType) !== "markdown" || !this.editor.markdown)
|
|
643
|
+
return y.insertContentAt(e, n, t);
|
|
644
|
+
const r = this.editor.markdown.parse(n);
|
|
645
|
+
return y.insertContentAt(e, r, t);
|
|
646
|
+
}
|
|
647
|
+
};
|
|
648
|
+
},
|
|
649
|
+
addStorage() {
|
|
650
|
+
return {
|
|
651
|
+
manager: new I({
|
|
652
|
+
indentation: this.options.indentation,
|
|
653
|
+
marked: this.options.marked,
|
|
654
|
+
markedOptions: this.options.markedOptions,
|
|
655
|
+
extensions: []
|
|
656
|
+
})
|
|
657
|
+
};
|
|
658
|
+
},
|
|
659
|
+
onBeforeCreate() {
|
|
660
|
+
if (this.editor.markdown) {
|
|
661
|
+
console.error(
|
|
662
|
+
"[tiptap][markdown]: There is already a `markdown` property on the editor instance. This might lead to unexpected behavior."
|
|
663
|
+
);
|
|
664
|
+
return;
|
|
665
|
+
}
|
|
666
|
+
if (this.storage.manager = new I({
|
|
667
|
+
indentation: this.options.indentation,
|
|
668
|
+
marked: this.options.marked,
|
|
669
|
+
markedOptions: this.options.markedOptions,
|
|
670
|
+
extensions: this.editor.extensionManager.baseExtensions
|
|
671
|
+
}), this.editor.markdown = this.storage.manager, this.editor.getMarkdown = () => this.storage.manager.serialize(this.editor.getJSON()), !this.editor.options.contentType || E(this.editor.options.content, this.editor.options.contentType) !== "markdown")
|
|
672
|
+
return;
|
|
673
|
+
if (!this.editor.markdown)
|
|
674
|
+
throw new Error(
|
|
675
|
+
'[tiptap][markdown]: The `contentType` option is set to "markdown", but the Markdown extension is not added to the editor. Please add the Markdown extension to use this feature.'
|
|
676
|
+
);
|
|
677
|
+
if (this.editor.options.content === void 0 || typeof this.editor.options.content != "string")
|
|
678
|
+
throw new Error(
|
|
679
|
+
'[tiptap][markdown]: The `contentType` option is set to "markdown", but the initial content is not a string. Please provide the initial content as a markdown string.'
|
|
680
|
+
);
|
|
681
|
+
const n = this.editor.markdown.parse(this.editor.options.content);
|
|
682
|
+
this.editor.options.content = n;
|
|
683
|
+
}
|
|
684
|
+
});
|
|
3
685
|
export {
|
|
4
|
-
|
|
5
|
-
|
|
686
|
+
q as Markdown,
|
|
687
|
+
j as MarkdownManager,
|
|
688
|
+
E as assumeContentType,
|
|
689
|
+
N as closeMarksBeforeNode,
|
|
690
|
+
O as findMarksToClose,
|
|
691
|
+
$ as findMarksToCloseAtEnd,
|
|
692
|
+
F as findMarksToOpen,
|
|
693
|
+
R as isTaskItem,
|
|
694
|
+
S as reopenMarksAfterNode,
|
|
695
|
+
_ as wrapInMarkdownBlock
|
|
6
696
|
};
|