@cocoar/vue-markdown-core 1.6.4 → 1.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +404 -460
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,483 +1,427 @@
1
- import { unified as k } from "unified";
2
- import C from "remark-parse";
3
- import v from "remark-gfm";
4
- import I from "remark-stringify";
5
- const R = 2166136261, A = 16777619;
6
- function B(t) {
7
- let e = R;
8
- for (let i = 0; i < t.length; i++)
9
- e ^= t.charCodeAt(i), e = Math.imul(e, A);
10
- return e >>> 0;
1
+ import { unified as e } from "unified";
2
+ import t from "remark-parse";
3
+ import n from "remark-gfm";
4
+ import r from "remark-stringify";
5
+ //#region src/lib/id.ts
6
+ var i = 2166136261, a = 16777619;
7
+ function o(e) {
8
+ let t = i;
9
+ for (let n = 0; n < e.length; n++) t ^= e.charCodeAt(n), t = Math.imul(t, a);
10
+ return t >>> 0;
11
11
  }
12
- function d(t) {
13
- return B(t).toString(36);
12
+ function s(e) {
13
+ return o(e).toString(36);
14
14
  }
15
- function K(t, e = {}) {
16
- const i = k().use(C);
17
- (e.gfm ?? !0) && i.use(v);
18
- const n = i.parse(t);
19
- return M(n);
15
+ //#endregion
16
+ //#region src/lib/parse.ts
17
+ function c(r, i = {}) {
18
+ let a = e().use(t);
19
+ return (i.gfm ?? !0) && a.use(n), l(a.parse(r));
20
20
  }
21
- function M(t) {
22
- const e = z(), i = T(t);
23
- return { nodes: t.children.map((l, r) => u(l, void 0, r, e, i)).filter(o) };
21
+ function l(e) {
22
+ let t = b(), n = u(e);
23
+ return { nodes: e.children.map((e, r) => f(e, void 0, r, t, n)).filter(d) };
24
24
  }
25
- function T(t) {
26
- const e = /* @__PURE__ */ new Map();
27
- for (const i of t.children) {
28
- if (i.type !== "definition") continue;
29
- const n = i, l = typeof n.identifier == "string" ? n.identifier : "", r = typeof n.url == "string" ? n.url : "", p = typeof n.title == "string" ? n.title : void 0;
30
- l.length === 0 || r.length === 0 || e.set(l, { url: r, title: p });
31
- }
32
- return e;
25
+ function u(e) {
26
+ let t = /* @__PURE__ */ new Map();
27
+ for (let n of e.children) {
28
+ if (n.type !== "definition") continue;
29
+ let e = n, r = typeof e.identifier == "string" ? e.identifier : "", i = typeof e.url == "string" ? e.url : "", a = typeof e.title == "string" ? e.title : void 0;
30
+ r.length === 0 || i.length === 0 || t.set(r, {
31
+ url: i,
32
+ title: a
33
+ });
34
+ }
35
+ return t;
33
36
  }
34
- function o(t) {
35
- return t !== null;
37
+ function d(e) {
38
+ return e !== null;
36
39
  }
37
- function u(t, e, i, n, l) {
38
- const r = O(t.position), p = `${t.type}|${r?.start ?? "na"}-${r?.end ?? "na"}|${e ?? "root"}|${i}`, s = d(p);
39
- switch (t.type) {
40
- case "heading":
41
- return N(t, s, r, n, l);
42
- case "paragraph":
43
- return {
44
- id: s,
45
- type: "paragraph",
46
- position: r,
47
- children: (t.children ?? []).map((a, c) => u(a, s, c, n, l)).filter(o)
48
- };
49
- case "blockquote":
50
- return {
51
- id: s,
52
- type: "blockquote",
53
- position: r,
54
- children: (t.children ?? []).map((a, c) => u(a, s, c, n, l)).filter(o)
55
- };
56
- case "list":
57
- return q(t, s, r, n, l);
58
- case "listItem":
59
- return F(t, s, r, n, l);
60
- case "code":
61
- return {
62
- id: s,
63
- type: "codeBlock",
64
- position: r,
65
- text: t.value,
66
- attrs: {
67
- language: t.lang ?? void 0,
68
- meta: t.meta ?? void 0
69
- }
70
- };
71
- case "inlineCode":
72
- return {
73
- id: s,
74
- type: "inlineCode",
75
- position: r,
76
- text: t.value
77
- };
78
- case "break":
79
- return {
80
- id: s,
81
- type: "lineBreak",
82
- position: r
83
- };
84
- case "text":
85
- return {
86
- id: s,
87
- type: "text",
88
- position: r,
89
- text: t.value
90
- };
91
- case "emphasis":
92
- return {
93
- id: s,
94
- type: "emphasis",
95
- position: r,
96
- children: (t.children ?? []).map((a, c) => u(a, s, c, n, l)).filter(o)
97
- };
98
- case "strong":
99
- return {
100
- id: s,
101
- type: "strong",
102
- position: r,
103
- children: (t.children ?? []).map((a, c) => u(a, s, c, n, l)).filter(o)
104
- };
105
- case "delete":
106
- return {
107
- id: s,
108
- type: "strikethrough",
109
- position: r,
110
- children: (t.children ?? []).map((a, c) => u(a, s, c, n, l)).filter(o)
111
- };
112
- case "link":
113
- return P(t, s, r, n, l);
114
- case "linkReference": {
115
- const a = t, c = typeof a.identifier == "string" ? a.identifier : "", f = c.length > 0 ? l.get(c) : void 0;
116
- if (!f?.url)
117
- return {
118
- id: s,
119
- type: "text",
120
- position: r,
121
- text: g(t)
122
- };
123
- const y = Array.isArray(a.children) ? a.children : [];
124
- return {
125
- id: s,
126
- type: "link",
127
- position: r,
128
- attrs: {
129
- url: f.url,
130
- title: f.title ?? void 0
131
- },
132
- children: y.map((b, m) => u(b, s, m, n, l)).filter(o)
133
- };
134
- }
135
- case "image": {
136
- const a = t, c = typeof a.url == "string" ? a.url : "", f = typeof a.title == "string" ? a.title : void 0, y = typeof a.alt == "string" ? a.alt : "";
137
- return c.length === 0 ? {
138
- id: s,
139
- type: "text",
140
- position: r,
141
- text: y
142
- } : {
143
- id: s,
144
- type: "image",
145
- position: r,
146
- attrs: {
147
- url: c,
148
- title: f,
149
- alt: y
150
- }
151
- };
152
- }
153
- case "imageReference": {
154
- const a = t, c = typeof a.identifier == "string" ? a.identifier : "", f = c.length > 0 ? l.get(c) : void 0, y = typeof a.alt == "string" ? a.alt : "";
155
- return f?.url ? {
156
- id: s,
157
- type: "image",
158
- position: r,
159
- attrs: {
160
- url: f.url,
161
- title: f.title ?? void 0,
162
- alt: y
163
- }
164
- } : {
165
- id: s,
166
- type: "text",
167
- position: r,
168
- text: y
169
- };
170
- }
171
- case "thematicBreak":
172
- return {
173
- id: s,
174
- type: "thematicBreak",
175
- position: r
176
- };
177
- case "table":
178
- return L(t, s, r, n, l);
179
- case "tableRow":
180
- return _(t, s, r, n, l);
181
- case "tableCell":
182
- return H(t, s, r, n, l);
183
- // Reference-style definitions should not render as visible content.
184
- case "definition":
185
- return null;
186
- // Footnotes are supported by remark-gfm but not rendered as interactive footnotes in v1.
187
- // Convert them to readable content instead of emitting unsupported placeholders.
188
- case "footnoteReference": {
189
- const a = t, c = typeof a.identifier == "string" ? a.identifier : typeof a.label == "string" ? a.label : "", f = c.length > 0 ? c : "?";
190
- return {
191
- id: s,
192
- type: "text",
193
- position: r,
194
- text: `[^${f}]`
195
- };
196
- }
197
- case "footnoteDefinition": {
198
- const a = t, c = typeof a.identifier == "string" ? a.identifier : typeof a.label == "string" ? a.label : "", f = c.length > 0 ? c : "?", y = d(`${p}|footnote-label-text`), m = {
199
- id: d(`${p}|footnote-label-paragraph`),
200
- type: "paragraph",
201
- position: r,
202
- children: [
203
- {
204
- id: y,
205
- type: "text",
206
- position: r,
207
- text: `[^${f}]: `
208
- }
209
- ]
210
- }, x = Array.isArray(a.children) ? a.children : [];
211
- return {
212
- id: s,
213
- type: "blockquote",
214
- position: r,
215
- children: [
216
- m,
217
- ...x.map(($, w) => u($, s, w, n, l)).filter(o)
218
- ]
219
- };
220
- }
221
- // Raw HTML is intentionally unsupported in v1.
222
- case "html":
223
- return {
224
- id: s,
225
- type: "unsupported",
226
- position: r,
227
- attrs: { originalType: "html" },
228
- text: t.value
229
- };
230
- default:
231
- return {
232
- id: s,
233
- // Preserve the original type string for better diagnostics.
234
- type: "unsupported",
235
- position: r,
236
- attrs: { originalType: t.type }
237
- };
238
- }
40
+ function f(e, t, n, r, i) {
41
+ let a = C(e.position), o = `${e.type}|${a?.start ?? "na"}-${a?.end ?? "na"}|${t ?? "root"}|${n}`, c = s(o);
42
+ switch (e.type) {
43
+ case "heading": return p(e, c, a, r, i);
44
+ case "paragraph": return {
45
+ id: c,
46
+ type: "paragraph",
47
+ position: a,
48
+ children: (e.children ?? []).map((e, t) => f(e, c, t, r, i)).filter(d)
49
+ };
50
+ case "blockquote": return {
51
+ id: c,
52
+ type: "blockquote",
53
+ position: a,
54
+ children: (e.children ?? []).map((e, t) => f(e, c, t, r, i)).filter(d)
55
+ };
56
+ case "list": return h(e, c, a, r, i);
57
+ case "listItem": return g(e, c, a, r, i);
58
+ case "code": return {
59
+ id: c,
60
+ type: "codeBlock",
61
+ position: a,
62
+ text: e.value,
63
+ attrs: {
64
+ language: e.lang ?? void 0,
65
+ meta: e.meta ?? void 0
66
+ }
67
+ };
68
+ case "inlineCode": return {
69
+ id: c,
70
+ type: "inlineCode",
71
+ position: a,
72
+ text: e.value
73
+ };
74
+ case "break": return {
75
+ id: c,
76
+ type: "lineBreak",
77
+ position: a
78
+ };
79
+ case "text": return {
80
+ id: c,
81
+ type: "text",
82
+ position: a,
83
+ text: e.value
84
+ };
85
+ case "emphasis": return {
86
+ id: c,
87
+ type: "emphasis",
88
+ position: a,
89
+ children: (e.children ?? []).map((e, t) => f(e, c, t, r, i)).filter(d)
90
+ };
91
+ case "strong": return {
92
+ id: c,
93
+ type: "strong",
94
+ position: a,
95
+ children: (e.children ?? []).map((e, t) => f(e, c, t, r, i)).filter(d)
96
+ };
97
+ case "delete": return {
98
+ id: c,
99
+ type: "strikethrough",
100
+ position: a,
101
+ children: (e.children ?? []).map((e, t) => f(e, c, t, r, i)).filter(d)
102
+ };
103
+ case "link": return m(e, c, a, r, i);
104
+ case "linkReference": {
105
+ let t = e, n = typeof t.identifier == "string" ? t.identifier : "", o = n.length > 0 ? i.get(n) : void 0;
106
+ if (!o?.url) return {
107
+ id: c,
108
+ type: "text",
109
+ position: a,
110
+ text: S(e)
111
+ };
112
+ let s = Array.isArray(t.children) ? t.children : [];
113
+ return {
114
+ id: c,
115
+ type: "link",
116
+ position: a,
117
+ attrs: {
118
+ url: o.url,
119
+ title: o.title ?? void 0
120
+ },
121
+ children: s.map((e, t) => f(e, c, t, r, i)).filter(d)
122
+ };
123
+ }
124
+ case "image": {
125
+ let t = e, n = typeof t.url == "string" ? t.url : "", r = typeof t.title == "string" ? t.title : void 0, i = typeof t.alt == "string" ? t.alt : "";
126
+ return n.length === 0 ? {
127
+ id: c,
128
+ type: "text",
129
+ position: a,
130
+ text: i
131
+ } : {
132
+ id: c,
133
+ type: "image",
134
+ position: a,
135
+ attrs: {
136
+ url: n,
137
+ title: r,
138
+ alt: i
139
+ }
140
+ };
141
+ }
142
+ case "imageReference": {
143
+ let t = e, n = typeof t.identifier == "string" ? t.identifier : "", r = n.length > 0 ? i.get(n) : void 0, o = typeof t.alt == "string" ? t.alt : "";
144
+ return r?.url ? {
145
+ id: c,
146
+ type: "image",
147
+ position: a,
148
+ attrs: {
149
+ url: r.url,
150
+ title: r.title ?? void 0,
151
+ alt: o
152
+ }
153
+ } : {
154
+ id: c,
155
+ type: "text",
156
+ position: a,
157
+ text: o
158
+ };
159
+ }
160
+ case "thematicBreak": return {
161
+ id: c,
162
+ type: "thematicBreak",
163
+ position: a
164
+ };
165
+ case "table": return _(e, c, a, r, i);
166
+ case "tableRow": return v(e, c, a, r, i);
167
+ case "tableCell": return y(e, c, a, r, i);
168
+ case "definition": return null;
169
+ case "footnoteReference": {
170
+ let t = e, n = typeof t.identifier == "string" ? t.identifier : typeof t.label == "string" ? t.label : "";
171
+ return {
172
+ id: c,
173
+ type: "text",
174
+ position: a,
175
+ text: `[^${n.length > 0 ? n : "?"}]`
176
+ };
177
+ }
178
+ case "footnoteDefinition": {
179
+ let t = e, n = typeof t.identifier == "string" ? t.identifier : typeof t.label == "string" ? t.label : "", l = n.length > 0 ? n : "?", u = s(`${o}|footnote-label-text`);
180
+ return {
181
+ id: c,
182
+ type: "blockquote",
183
+ position: a,
184
+ children: [{
185
+ id: s(`${o}|footnote-label-paragraph`),
186
+ type: "paragraph",
187
+ position: a,
188
+ children: [{
189
+ id: u,
190
+ type: "text",
191
+ position: a,
192
+ text: `[^${l}]: `
193
+ }]
194
+ }, ...(Array.isArray(t.children) ? t.children : []).map((e, t) => f(e, c, t, r, i)).filter(d)]
195
+ };
196
+ }
197
+ case "html": return {
198
+ id: c,
199
+ type: "unsupported",
200
+ position: a,
201
+ attrs: { originalType: "html" },
202
+ text: e.value
203
+ };
204
+ default: return {
205
+ id: c,
206
+ type: "unsupported",
207
+ position: a,
208
+ attrs: { originalType: e.type }
209
+ };
210
+ }
239
211
  }
240
- function N(t, e, i, n, l) {
241
- const r = g(t), p = r.length > 0 ? n.slug(r) : void 0;
242
- return {
243
- id: e,
244
- type: "heading",
245
- position: i,
246
- attrs: { depth: t.depth, anchor: p },
247
- children: (t.children ?? []).map((s, a) => u(s, e, a, n, l)).filter(o)
248
- };
212
+ function p(e, t, n, r, i) {
213
+ let a = S(e), o = a.length > 0 ? r.slug(a) : void 0;
214
+ return {
215
+ id: t,
216
+ type: "heading",
217
+ position: n,
218
+ attrs: {
219
+ depth: e.depth,
220
+ anchor: o
221
+ },
222
+ children: (e.children ?? []).map((e, n) => f(e, t, n, r, i)).filter(d)
223
+ };
249
224
  }
250
- function P(t, e, i, n, l) {
251
- return {
252
- id: e,
253
- type: "link",
254
- position: i,
255
- attrs: {
256
- url: t.url,
257
- title: t.title ?? void 0
258
- },
259
- children: (t.children ?? []).map((r, p) => u(r, e, p, n, l)).filter(o)
260
- };
225
+ function m(e, t, n, r, i) {
226
+ return {
227
+ id: t,
228
+ type: "link",
229
+ position: n,
230
+ attrs: {
231
+ url: e.url,
232
+ title: e.title ?? void 0
233
+ },
234
+ children: (e.children ?? []).map((e, n) => f(e, t, n, r, i)).filter(d)
235
+ };
261
236
  }
262
- function q(t, e, i, n, l) {
263
- return {
264
- id: e,
265
- type: "list",
266
- position: i,
267
- attrs: {
268
- ordered: t.ordered ?? !1,
269
- start: t.start ?? void 0,
270
- spread: t.spread ?? void 0
271
- },
272
- children: (t.children ?? []).map((r, p) => u(r, e, p, n, l)).filter(o)
273
- };
237
+ function h(e, t, n, r, i) {
238
+ return {
239
+ id: t,
240
+ type: "list",
241
+ position: n,
242
+ attrs: {
243
+ ordered: e.ordered ?? !1,
244
+ start: e.start ?? void 0,
245
+ spread: e.spread ?? void 0
246
+ },
247
+ children: (e.children ?? []).map((e, n) => f(e, t, n, r, i)).filter(d)
248
+ };
274
249
  }
275
- function F(t, e, i, n, l) {
276
- return {
277
- id: e,
278
- type: "listItem",
279
- position: i,
280
- attrs: {
281
- checked: t.checked ?? void 0,
282
- spread: t.spread ?? void 0
283
- },
284
- children: (t.children ?? []).map((r, p) => u(r, e, p, n, l)).filter(o)
285
- };
250
+ function g(e, t, n, r, i) {
251
+ return {
252
+ id: t,
253
+ type: "listItem",
254
+ position: n,
255
+ attrs: {
256
+ checked: e.checked ?? void 0,
257
+ spread: e.spread ?? void 0
258
+ },
259
+ children: (e.children ?? []).map((e, n) => f(e, t, n, r, i)).filter(d)
260
+ };
286
261
  }
287
- function L(t, e, i, n, l) {
288
- return {
289
- id: e,
290
- type: "table",
291
- position: i,
292
- attrs: {
293
- align: t.align ?? void 0
294
- },
295
- children: (t.children ?? []).map((r, p) => u(r, e, p, n, l)).filter(o)
296
- };
262
+ function _(e, t, n, r, i) {
263
+ return {
264
+ id: t,
265
+ type: "table",
266
+ position: n,
267
+ attrs: { align: e.align ?? void 0 },
268
+ children: (e.children ?? []).map((e, n) => f(e, t, n, r, i)).filter(d)
269
+ };
297
270
  }
298
- function _(t, e, i, n, l) {
299
- return {
300
- id: e,
301
- type: "tableRow",
302
- position: i,
303
- children: (t.children ?? []).map((r, p) => u(r, e, p, n, l)).filter(o)
304
- };
271
+ function v(e, t, n, r, i) {
272
+ return {
273
+ id: t,
274
+ type: "tableRow",
275
+ position: n,
276
+ children: (e.children ?? []).map((e, n) => f(e, t, n, r, i)).filter(d)
277
+ };
305
278
  }
306
- function H(t, e, i, n, l) {
307
- return {
308
- id: e,
309
- type: "tableCell",
310
- position: i,
311
- children: (t.children ?? []).map((r, p) => u(r, e, p, n, l)).filter(o)
312
- };
279
+ function y(e, t, n, r, i) {
280
+ return {
281
+ id: t,
282
+ type: "tableCell",
283
+ position: n,
284
+ children: (e.children ?? []).map((e, n) => f(e, t, n, r, i)).filter(d)
285
+ };
313
286
  }
314
- function z() {
315
- const t = /* @__PURE__ */ new Map();
316
- return {
317
- slug(e) {
318
- const i = D(e), n = t.get(i) ?? 0;
319
- return t.set(i, n + 1), n === 0 ? i : `${i}-${n}`;
320
- }
321
- };
287
+ function b() {
288
+ let e = /* @__PURE__ */ new Map();
289
+ return { slug(t) {
290
+ let n = x(t), r = e.get(n) ?? 0;
291
+ return e.set(n, r + 1), r === 0 ? n : `${n}-${r}`;
292
+ } };
322
293
  }
323
- function D(t) {
324
- const i = t.trim().toLowerCase().replace(/[^\p{L}\p{N}\s-]+/gu, "").replace(/\s+/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
325
- return i.length > 0 ? i : "section";
294
+ function x(e) {
295
+ let t = e.trim().toLowerCase().replace(/[^\p{L}\p{N}\s-]+/gu, "").replace(/\s+/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
296
+ return t.length > 0 ? t : "section";
326
297
  }
327
- function g(t) {
328
- if (!t || typeof t != "object") return "";
329
- const e = t;
330
- return typeof e.type != "string" ? "" : e.type === "text" || e.type === "inlineCode" ? typeof e.value == "string" ? e.value : "" : (Array.isArray(e.children) ? e.children : []).map((n) => g(n)).join("");
298
+ function S(e) {
299
+ if (!e || typeof e != "object") return "";
300
+ let t = e;
301
+ return typeof t.type == "string" ? t.type === "text" || t.type === "inlineCode" ? typeof t.value == "string" ? t.value : "" : (Array.isArray(t.children) ? t.children : []).map((e) => S(e)).join("") : "";
331
302
  }
332
- function O(t) {
333
- const e = t;
334
- if (!e?.start || !e?.end)
335
- return;
336
- const i = e.start.offset, n = e.end.offset, l = e.start.line, r = e.start.column;
337
- if (!(typeof i != "number" || typeof n != "number" || typeof l != "number" || typeof r != "number"))
338
- return {
339
- start: i,
340
- end: n,
341
- line: l,
342
- column: r
343
- };
303
+ function C(e) {
304
+ let t = e;
305
+ if (!t?.start || !t?.end) return;
306
+ let n = t.start.offset, r = t.end.offset, i = t.start.line, a = t.start.column;
307
+ if (!(typeof n != "number" || typeof r != "number" || typeof i != "number" || typeof a != "number")) return {
308
+ start: n,
309
+ end: r,
310
+ line: i,
311
+ column: a
312
+ };
344
313
  }
345
- function Q(t, e = {}) {
346
- const i = V(t), n = k().use(I);
347
- return (e.gfm ?? !0) && n.use(v), String(n.stringify(i));
314
+ //#endregion
315
+ //#region src/lib/serialize.ts
316
+ function w(t, i = {}) {
317
+ let a = T(t), o = e().use(r);
318
+ return (i.gfm ?? !0) && o.use(n), String(o.stringify(a));
348
319
  }
349
- function V(t) {
350
- return {
351
- type: "root",
352
- children: t.nodes.map((e) => h(e))
353
- };
320
+ function T(e) {
321
+ return {
322
+ type: "root",
323
+ children: e.nodes.map((e) => E(e))
324
+ };
354
325
  }
355
- function h(t) {
356
- switch (t.type) {
357
- case "heading":
358
- return {
359
- type: "heading",
360
- depth: j(t.attrs?.depth),
361
- children: (t.children ?? []).map(h)
362
- };
363
- case "paragraph":
364
- return {
365
- type: "paragraph",
366
- children: (t.children ?? []).map(h)
367
- };
368
- case "blockquote":
369
- return {
370
- type: "blockquote",
371
- children: (t.children ?? []).map(h)
372
- };
373
- case "list":
374
- return {
375
- type: "list",
376
- ordered: !!t.attrs?.ordered,
377
- start: typeof t.attrs?.start == "number" ? t.attrs.start : void 0,
378
- spread: typeof t.attrs?.spread == "boolean" ? t.attrs.spread : void 0,
379
- children: (t.children ?? []).map(h)
380
- };
381
- case "listItem":
382
- return {
383
- type: "listItem",
384
- checked: typeof t.attrs?.checked == "boolean" ? t.attrs.checked : null,
385
- spread: typeof t.attrs?.spread == "boolean" ? t.attrs.spread : void 0,
386
- children: (t.children ?? []).map(h)
387
- };
388
- case "codeBlock":
389
- return {
390
- type: "code",
391
- lang: typeof t.attrs?.language == "string" ? t.attrs.language : null,
392
- meta: typeof t.attrs?.meta == "string" ? t.attrs.meta : null,
393
- value: t.text ?? ""
394
- };
395
- case "inlineCode":
396
- return {
397
- type: "inlineCode",
398
- value: t.text ?? ""
399
- };
400
- case "text":
401
- return {
402
- type: "text",
403
- value: t.text ?? ""
404
- };
405
- case "emphasis":
406
- return {
407
- type: "emphasis",
408
- children: (t.children ?? []).map(h)
409
- };
410
- case "strong":
411
- return {
412
- type: "strong",
413
- children: (t.children ?? []).map(h)
414
- };
415
- case "strikethrough":
416
- return {
417
- type: "delete",
418
- children: (t.children ?? []).map(h)
419
- };
420
- case "link":
421
- return {
422
- type: "link",
423
- url: typeof t.attrs?.url == "string" ? t.attrs.url : "",
424
- title: typeof t.attrs?.title == "string" ? t.attrs.title : null,
425
- children: (t.children ?? []).map(h)
426
- };
427
- case "image":
428
- return {
429
- type: "image",
430
- url: typeof t.attrs?.url == "string" ? t.attrs.url : "",
431
- title: typeof t.attrs?.title == "string" ? t.attrs.title : null,
432
- alt: typeof t.attrs?.alt == "string" ? t.attrs.alt : ""
433
- };
434
- case "thematicBreak":
435
- return {
436
- type: "thematicBreak"
437
- };
438
- case "lineBreak":
439
- return {
440
- type: "break"
441
- };
442
- case "table":
443
- return {
444
- type: "table",
445
- align: Array.isArray(t.attrs?.align) ? t.attrs.align : void 0,
446
- children: (t.children ?? []).map(h)
447
- };
448
- case "tableRow":
449
- return {
450
- type: "tableRow",
451
- children: (t.children ?? []).map(h)
452
- };
453
- case "tableCell":
454
- return {
455
- type: "tableCell",
456
- children: (t.children ?? []).map(h)
457
- };
458
- case "unsupported":
459
- return {
460
- type: "html",
461
- value: `<!-- Unsupported node: ${String(t.attrs?.originalType ?? "unknown")} -->`
462
- };
463
- default:
464
- return {
465
- type: "html",
466
- value: `<!-- Unsupported node: ${String(t.type)} -->`
467
- };
468
- }
326
+ function E(e) {
327
+ switch (e.type) {
328
+ case "heading": return {
329
+ type: "heading",
330
+ depth: D(e.attrs?.depth),
331
+ children: (e.children ?? []).map(E)
332
+ };
333
+ case "paragraph": return {
334
+ type: "paragraph",
335
+ children: (e.children ?? []).map(E)
336
+ };
337
+ case "blockquote": return {
338
+ type: "blockquote",
339
+ children: (e.children ?? []).map(E)
340
+ };
341
+ case "list": return {
342
+ type: "list",
343
+ ordered: !!e.attrs?.ordered,
344
+ start: typeof e.attrs?.start == "number" ? e.attrs.start : void 0,
345
+ spread: typeof e.attrs?.spread == "boolean" ? e.attrs.spread : void 0,
346
+ children: (e.children ?? []).map(E)
347
+ };
348
+ case "listItem": return {
349
+ type: "listItem",
350
+ checked: typeof e.attrs?.checked == "boolean" ? e.attrs.checked : null,
351
+ spread: typeof e.attrs?.spread == "boolean" ? e.attrs.spread : void 0,
352
+ children: (e.children ?? []).map(E)
353
+ };
354
+ case "codeBlock": return {
355
+ type: "code",
356
+ lang: typeof e.attrs?.language == "string" ? e.attrs.language : null,
357
+ meta: typeof e.attrs?.meta == "string" ? e.attrs.meta : null,
358
+ value: e.text ?? ""
359
+ };
360
+ case "inlineCode": return {
361
+ type: "inlineCode",
362
+ value: e.text ?? ""
363
+ };
364
+ case "text": return {
365
+ type: "text",
366
+ value: e.text ?? ""
367
+ };
368
+ case "emphasis": return {
369
+ type: "emphasis",
370
+ children: (e.children ?? []).map(E)
371
+ };
372
+ case "strong": return {
373
+ type: "strong",
374
+ children: (e.children ?? []).map(E)
375
+ };
376
+ case "strikethrough": return {
377
+ type: "delete",
378
+ children: (e.children ?? []).map(E)
379
+ };
380
+ case "link": return {
381
+ type: "link",
382
+ url: typeof e.attrs?.url == "string" ? e.attrs.url : "",
383
+ title: typeof e.attrs?.title == "string" ? e.attrs.title : null,
384
+ children: (e.children ?? []).map(E)
385
+ };
386
+ case "image": return {
387
+ type: "image",
388
+ url: typeof e.attrs?.url == "string" ? e.attrs.url : "",
389
+ title: typeof e.attrs?.title == "string" ? e.attrs.title : null,
390
+ alt: typeof e.attrs?.alt == "string" ? e.attrs.alt : ""
391
+ };
392
+ case "thematicBreak": return { type: "thematicBreak" };
393
+ case "lineBreak": return { type: "break" };
394
+ case "table": return {
395
+ type: "table",
396
+ align: Array.isArray(e.attrs?.align) ? e.attrs.align : void 0,
397
+ children: (e.children ?? []).map(E)
398
+ };
399
+ case "tableRow": return {
400
+ type: "tableRow",
401
+ children: (e.children ?? []).map(E)
402
+ };
403
+ case "tableCell": return {
404
+ type: "tableCell",
405
+ children: (e.children ?? []).map(E)
406
+ };
407
+ case "unsupported": return {
408
+ type: "html",
409
+ value: `<!-- Unsupported node: ${String(e.attrs?.originalType ?? "unknown")} -->`
410
+ };
411
+ default: return {
412
+ type: "html",
413
+ value: `<!-- Unsupported node: ${String(e.type)} -->`
414
+ };
415
+ }
469
416
  }
470
- function j(t) {
471
- const e = typeof t == "number" ? Math.trunc(t) : 1;
472
- return e <= 1 ? 1 : e === 2 ? 2 : e === 3 ? 3 : e === 4 ? 4 : e === 5 ? 5 : 6;
417
+ function D(e) {
418
+ let t = typeof e == "number" ? Math.trunc(e) : 1;
419
+ return t <= 1 ? 1 : t === 2 ? 2 : t === 3 ? 3 : t === 4 ? 4 : t === 5 ? 5 : 6;
473
420
  }
474
- function W(t, ...e) {
475
- return e.reduce((i, n) => n(i), t);
421
+ //#endregion
422
+ //#region src/lib/transform.ts
423
+ function O(e, ...t) {
424
+ return t.reduce((e, t) => t(e), e);
476
425
  }
477
- export {
478
- d as createNodeId,
479
- B as hashStringFNV1a32,
480
- K as parse,
481
- Q as serialize,
482
- W as transform
483
- };
426
+ //#endregion
427
+ export { s as createNodeId, o as hashStringFNV1a32, c as parse, w as serialize, O as transform };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocoar/vue-markdown-core",
3
- "version": "1.6.4",
3
+ "version": "1.6.5",
4
4
  "description": "Core markdown parsing utilities for @cocoar/vue-markdown",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {