@cocoar/vue-markdown-core 1.14.0 → 1.16.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/index.d.ts CHANGED
@@ -3,4 +3,5 @@ export * from './lib/parse';
3
3
  export * from './lib/serialize';
4
4
  export * from './lib/transform';
5
5
  export * from './lib/id';
6
+ export * from './lib/color-span';
6
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC"}
package/dist/index.js CHANGED
@@ -13,16 +13,139 @@ function s(e) {
13
13
  return o(e).toString(36);
14
14
  }
15
15
  //#endregion
16
+ //#region src/lib/color-span.ts
17
+ var c = new Set([
18
+ "black",
19
+ "silver",
20
+ "gray",
21
+ "white",
22
+ "maroon",
23
+ "red",
24
+ "purple",
25
+ "fuchsia",
26
+ "green",
27
+ "lime",
28
+ "olive",
29
+ "yellow",
30
+ "navy",
31
+ "blue",
32
+ "teal",
33
+ "aqua",
34
+ "orange",
35
+ "transparent",
36
+ "currentcolor"
37
+ ]), l = /^#(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i, u = /^rgba?\(\s*\d{1,3}(?:\s*,\s*\d{1,3}){2}(?:\s*,\s*(?:0|1|0?\.\d+))?\s*\)$/i, d = /^rgba?\(\s*\d{1,3}(?:%|)(?:\s+\d{1,3}(?:%|)){2}(?:\s*\/\s*(?:0|1|0?\.\d+|\d{1,3}%))?\s*\)$/i, f = /^hsla?\(\s*-?\d+(?:\.\d+)?(?:deg|rad|grad|turn)?\s*,\s*\d{1,3}%\s*,\s*\d{1,3}%(?:\s*,\s*(?:0|1|0?\.\d+))?\s*\)$/i, p = /^hsla?\(\s*-?\d+(?:\.\d+)?(?:deg|rad|grad|turn)?\s+\d{1,3}%\s+\d{1,3}%(?:\s*\/\s*(?:0|1|0?\.\d+|\d{1,3}%))?\s*\)$/i;
38
+ function m(e) {
39
+ let t = e.trim();
40
+ if (t.length === 0 || t.length > 64 || t.includes(";") || t.includes("/*") || t.includes("*/") || t.includes("<") || t.includes(">") || t.includes("\\") || t.includes("\"") || t.includes("'")) return null;
41
+ if (t.includes("(")) {
42
+ let e = t.slice(0, t.indexOf("(")).trim().toLowerCase();
43
+ if (e !== "rgb" && e !== "rgba" && e !== "hsl" && e !== "hsla") return null;
44
+ }
45
+ if (l.test(t)) return t.toLowerCase();
46
+ if (u.test(t) || d.test(t) || f.test(t) || p.test(t)) return t;
47
+ let n = t.toLowerCase();
48
+ return c.has(n) ? n : null;
49
+ }
50
+ function h(e) {
51
+ let t = e.trim().replace(/;\s*$/, "");
52
+ if (t.length === 0 || t.includes(";")) return null;
53
+ let n = t.indexOf(":");
54
+ return n < 0 || t.slice(0, n).trim().toLowerCase() !== "color" ? null : m(t.slice(n + 1));
55
+ }
56
+ var g = /^<\s*span\b([^>]*?)>$/i, _ = /^<\s*\/\s*span\s*>$/i;
57
+ function v(e) {
58
+ let t = e.trim();
59
+ if (!g.test(t)) return null;
60
+ let n = (g.exec(t)?.[1] ?? "").trim();
61
+ if (n.length === 0) return null;
62
+ let r = /^style\s*=\s*(?:"([^"]*)"|'([^']*)')\s*$/i.exec(n);
63
+ if (!r) return null;
64
+ let i = h(r[1] ?? r[2] ?? "");
65
+ return i === null ? null : { color: i };
66
+ }
67
+ function y(e) {
68
+ return _.test(e.trim());
69
+ }
70
+ function b(e) {
71
+ return `<span style="color: ${e}">`;
72
+ }
73
+ function x() {
74
+ return "</span>";
75
+ }
76
+ //#endregion
16
77
  //#region src/lib/parse.ts
17
- function c(r, i = {}) {
78
+ function S(r, i = {}) {
18
79
  let a = e().use(t);
19
- return (i.gfm ?? !0) && a.use(n), l(a.parse(r));
80
+ return (i.gfm ?? !0) && a.use(n), C(a.parse(r));
20
81
  }
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) };
82
+ function C(e) {
83
+ let t = z(), n = k(e);
84
+ return { nodes: w(e.children.map((e, r) => j(e, void 0, r, t, n)).filter(A)) };
85
+ }
86
+ function w(e) {
87
+ return D(e.map((e) => {
88
+ if (!e.children) return e;
89
+ let t = w(e.children);
90
+ return T(e.children, t) ? e : {
91
+ ...e,
92
+ children: t
93
+ };
94
+ }));
95
+ }
96
+ function T(e, t) {
97
+ if (e.length !== t.length) return !1;
98
+ for (let n = 0; n < e.length; n++) if (e[n] !== t[n]) return !1;
99
+ return !0;
24
100
  }
25
- function u(e) {
101
+ function E(e) {
102
+ return e.type === "unsupported" && e.attrs?.originalType === "html" && typeof e.text == "string";
103
+ }
104
+ function D(e) {
105
+ let t = [], n = 0;
106
+ for (; n < e.length;) {
107
+ let r = e[n];
108
+ if (E(r)) {
109
+ let i = v(r.text);
110
+ if (i) {
111
+ let a = O(e, n);
112
+ if (a !== null) {
113
+ let o = D(e.slice(n + 1, a)), c = e[a]?.position, l = r.position?.start, u = c?.end, d = typeof l == "number" && typeof u == "number" && r.position && c ? {
114
+ start: l,
115
+ end: u,
116
+ line: r.position.line,
117
+ column: r.position.column
118
+ } : void 0;
119
+ t.push({
120
+ id: s(`colorSpan|${r.id}`),
121
+ type: "colorSpan",
122
+ position: d,
123
+ attrs: { color: i.color },
124
+ children: o
125
+ }), n = a + 1;
126
+ continue;
127
+ }
128
+ }
129
+ }
130
+ t.push(r), n++;
131
+ }
132
+ return t;
133
+ }
134
+ function O(e, t) {
135
+ let n = 1;
136
+ for (let r = t + 1; r < e.length; r++) {
137
+ let t = e[r];
138
+ if (E(t)) {
139
+ if (v(t.text)) {
140
+ n++;
141
+ continue;
142
+ }
143
+ if (y(t.text) && (n--, n === 0)) return r;
144
+ }
145
+ }
146
+ return null;
147
+ }
148
+ function k(e) {
26
149
  let t = /* @__PURE__ */ new Map();
27
150
  for (let n of e.children) {
28
151
  if (n.type !== "definition") continue;
@@ -34,27 +157,27 @@ function u(e) {
34
157
  }
35
158
  return t;
36
159
  }
37
- function d(e) {
160
+ function A(e) {
38
161
  return e !== null;
39
162
  }
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);
163
+ function j(e, t, n, r, i) {
164
+ let a = H(e.position), o = `${e.type}|${a?.start ?? "na"}-${a?.end ?? "na"}|${t ?? "root"}|${n}`, c = s(o);
42
165
  switch (e.type) {
43
- case "heading": return p(e, c, a, r, i);
166
+ case "heading": return M(e, c, a, r, i);
44
167
  case "paragraph": return {
45
168
  id: c,
46
169
  type: "paragraph",
47
170
  position: a,
48
- children: (e.children ?? []).map((e, t) => f(e, c, t, r, i)).filter(d)
171
+ children: (e.children ?? []).map((e, t) => j(e, c, t, r, i)).filter(A)
49
172
  };
50
173
  case "blockquote": return {
51
174
  id: c,
52
175
  type: "blockquote",
53
176
  position: a,
54
- children: (e.children ?? []).map((e, t) => f(e, c, t, r, i)).filter(d)
177
+ children: (e.children ?? []).map((e, t) => j(e, c, t, r, i)).filter(A)
55
178
  };
56
- case "list": return h(e, c, a, r, i);
57
- case "listItem": return g(e, c, a, r, i);
179
+ case "list": return P(e, c, a, r, i);
180
+ case "listItem": return F(e, c, a, r, i);
58
181
  case "code": return {
59
182
  id: c,
60
183
  type: "codeBlock",
@@ -86,28 +209,28 @@ function f(e, t, n, r, i) {
86
209
  id: c,
87
210
  type: "emphasis",
88
211
  position: a,
89
- children: (e.children ?? []).map((e, t) => f(e, c, t, r, i)).filter(d)
212
+ children: (e.children ?? []).map((e, t) => j(e, c, t, r, i)).filter(A)
90
213
  };
91
214
  case "strong": return {
92
215
  id: c,
93
216
  type: "strong",
94
217
  position: a,
95
- children: (e.children ?? []).map((e, t) => f(e, c, t, r, i)).filter(d)
218
+ children: (e.children ?? []).map((e, t) => j(e, c, t, r, i)).filter(A)
96
219
  };
97
220
  case "delete": return {
98
221
  id: c,
99
222
  type: "strikethrough",
100
223
  position: a,
101
- children: (e.children ?? []).map((e, t) => f(e, c, t, r, i)).filter(d)
224
+ children: (e.children ?? []).map((e, t) => j(e, c, t, r, i)).filter(A)
102
225
  };
103
- case "link": return m(e, c, a, r, i);
226
+ case "link": return N(e, c, a, r, i);
104
227
  case "linkReference": {
105
228
  let t = e, n = typeof t.identifier == "string" ? t.identifier : "", o = n.length > 0 ? i.get(n) : void 0;
106
229
  if (!o?.url) return {
107
230
  id: c,
108
231
  type: "text",
109
232
  position: a,
110
- text: S(e)
233
+ text: V(e)
111
234
  };
112
235
  let s = Array.isArray(t.children) ? t.children : [];
113
236
  return {
@@ -118,7 +241,7 @@ function f(e, t, n, r, i) {
118
241
  url: o.url,
119
242
  title: o.title ?? void 0
120
243
  },
121
- children: s.map((e, t) => f(e, c, t, r, i)).filter(d)
244
+ children: s.map((e, t) => j(e, c, t, r, i)).filter(A)
122
245
  };
123
246
  }
124
247
  case "image": {
@@ -162,9 +285,9 @@ function f(e, t, n, r, i) {
162
285
  type: "thematicBreak",
163
286
  position: a
164
287
  };
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);
288
+ case "table": return I(e, c, a, r, i);
289
+ case "tableRow": return L(e, c, a, r, i);
290
+ case "tableCell": return R(e, c, a, r, i);
168
291
  case "definition": return null;
169
292
  case "footnoteReference": {
170
293
  let t = e, n = typeof t.identifier == "string" ? t.identifier : typeof t.label == "string" ? t.label : "";
@@ -191,7 +314,7 @@ function f(e, t, n, r, i) {
191
314
  position: a,
192
315
  text: `[^${l}]: `
193
316
  }]
194
- }, ...(Array.isArray(t.children) ? t.children : []).map((e, t) => f(e, c, t, r, i)).filter(d)]
317
+ }, ...(Array.isArray(t.children) ? t.children : []).map((e, t) => j(e, c, t, r, i)).filter(A)]
195
318
  };
196
319
  }
197
320
  case "html": return {
@@ -209,8 +332,8 @@ function f(e, t, n, r, i) {
209
332
  };
210
333
  }
211
334
  }
212
- function p(e, t, n, r, i) {
213
- let a = S(e), o = a.length > 0 ? r.slug(a) : void 0;
335
+ function M(e, t, n, r, i) {
336
+ let a = V(e), o = a.length > 0 ? r.slug(a) : void 0;
214
337
  return {
215
338
  id: t,
216
339
  type: "heading",
@@ -219,10 +342,10 @@ function p(e, t, n, r, i) {
219
342
  depth: e.depth,
220
343
  anchor: o
221
344
  },
222
- children: (e.children ?? []).map((e, n) => f(e, t, n, r, i)).filter(d)
345
+ children: (e.children ?? []).map((e, n) => j(e, t, n, r, i)).filter(A)
223
346
  };
224
347
  }
225
- function m(e, t, n, r, i) {
348
+ function N(e, t, n, r, i) {
226
349
  return {
227
350
  id: t,
228
351
  type: "link",
@@ -231,10 +354,10 @@ function m(e, t, n, r, i) {
231
354
  url: e.url,
232
355
  title: e.title ?? void 0
233
356
  },
234
- children: (e.children ?? []).map((e, n) => f(e, t, n, r, i)).filter(d)
357
+ children: (e.children ?? []).map((e, n) => j(e, t, n, r, i)).filter(A)
235
358
  };
236
359
  }
237
- function h(e, t, n, r, i) {
360
+ function P(e, t, n, r, i) {
238
361
  return {
239
362
  id: t,
240
363
  type: "list",
@@ -244,10 +367,10 @@ function h(e, t, n, r, i) {
244
367
  start: e.start ?? void 0,
245
368
  spread: e.spread ?? void 0
246
369
  },
247
- children: (e.children ?? []).map((e, n) => f(e, t, n, r, i)).filter(d)
370
+ children: (e.children ?? []).map((e, n) => j(e, t, n, r, i)).filter(A)
248
371
  };
249
372
  }
250
- function g(e, t, n, r, i) {
373
+ function F(e, t, n, r, i) {
251
374
  return {
252
375
  id: t,
253
376
  type: "listItem",
@@ -256,51 +379,51 @@ function g(e, t, n, r, i) {
256
379
  checked: e.checked ?? void 0,
257
380
  spread: e.spread ?? void 0
258
381
  },
259
- children: (e.children ?? []).map((e, n) => f(e, t, n, r, i)).filter(d)
382
+ children: (e.children ?? []).map((e, n) => j(e, t, n, r, i)).filter(A)
260
383
  };
261
384
  }
262
- function _(e, t, n, r, i) {
385
+ function I(e, t, n, r, i) {
263
386
  return {
264
387
  id: t,
265
388
  type: "table",
266
389
  position: n,
267
390
  attrs: { align: e.align ?? void 0 },
268
- children: (e.children ?? []).map((e, n) => f(e, t, n, r, i)).filter(d)
391
+ children: (e.children ?? []).map((e, n) => j(e, t, n, r, i)).filter(A)
269
392
  };
270
393
  }
271
- function v(e, t, n, r, i) {
394
+ function L(e, t, n, r, i) {
272
395
  return {
273
396
  id: t,
274
397
  type: "tableRow",
275
398
  position: n,
276
- children: (e.children ?? []).map((e, n) => f(e, t, n, r, i)).filter(d)
399
+ children: (e.children ?? []).map((e, n) => j(e, t, n, r, i)).filter(A)
277
400
  };
278
401
  }
279
- function y(e, t, n, r, i) {
402
+ function R(e, t, n, r, i) {
280
403
  return {
281
404
  id: t,
282
405
  type: "tableCell",
283
406
  position: n,
284
- children: (e.children ?? []).map((e, n) => f(e, t, n, r, i)).filter(d)
407
+ children: (e.children ?? []).map((e, n) => j(e, t, n, r, i)).filter(A)
285
408
  };
286
409
  }
287
- function b() {
410
+ function z() {
288
411
  let e = /* @__PURE__ */ new Map();
289
412
  return { slug(t) {
290
- let n = x(t), r = e.get(n) ?? 0;
413
+ let n = B(t), r = e.get(n) ?? 0;
291
414
  return e.set(n, r + 1), r === 0 ? n : `${n}-${r}`;
292
415
  } };
293
416
  }
294
- function x(e) {
417
+ function B(e) {
295
418
  let t = e.trim().toLowerCase().replace(/[^\p{L}\p{N}\s-]+/gu, "").replace(/\s+/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
296
419
  return t.length > 0 ? t : "section";
297
420
  }
298
- function S(e) {
421
+ function V(e) {
299
422
  if (!e || typeof e != "object") return "";
300
423
  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("") : "";
424
+ 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) => V(e)).join("") : "";
302
425
  }
303
- function C(e) {
426
+ function H(e) {
304
427
  let t = e;
305
428
  if (!t?.start || !t?.end) return;
306
429
  let n = t.start.offset, r = t.end.offset, i = t.start.line, a = t.start.column;
@@ -313,43 +436,60 @@ function C(e) {
313
436
  }
314
437
  //#endregion
315
438
  //#region src/lib/serialize.ts
316
- function w(t, i = {}) {
317
- let a = T(t), o = e().use(r);
439
+ function U(t, i = {}) {
440
+ let a = W(t), o = e().use(r);
318
441
  return (i.gfm ?? !0) && o.use(n), String(o.stringify(a));
319
442
  }
320
- function T(e) {
443
+ function W(e) {
321
444
  return {
322
445
  type: "root",
323
- children: e.nodes.map((e) => E(e))
446
+ children: e.nodes.flatMap((e) => G(e))
324
447
  };
325
448
  }
326
- function E(e) {
449
+ function G(e) {
450
+ if (e.type === "colorSpan") {
451
+ let t = typeof e.attrs?.color == "string" ? e.attrs.color : null;
452
+ return t ? [
453
+ {
454
+ type: "html",
455
+ value: b(t)
456
+ },
457
+ ...(e.children ?? []).flatMap(G),
458
+ {
459
+ type: "html",
460
+ value: x()
461
+ }
462
+ ] : (e.children ?? []).flatMap(G);
463
+ }
464
+ return [K(e)];
465
+ }
466
+ function K(e) {
327
467
  switch (e.type) {
328
468
  case "heading": return {
329
469
  type: "heading",
330
- depth: D(e.attrs?.depth),
331
- children: (e.children ?? []).map(E)
470
+ depth: q(e.attrs?.depth),
471
+ children: (e.children ?? []).flatMap(G)
332
472
  };
333
473
  case "paragraph": return {
334
474
  type: "paragraph",
335
- children: (e.children ?? []).map(E)
475
+ children: (e.children ?? []).flatMap(G)
336
476
  };
337
477
  case "blockquote": return {
338
478
  type: "blockquote",
339
- children: (e.children ?? []).map(E)
479
+ children: (e.children ?? []).flatMap(G)
340
480
  };
341
481
  case "list": return {
342
482
  type: "list",
343
483
  ordered: !!e.attrs?.ordered,
344
484
  start: typeof e.attrs?.start == "number" ? e.attrs.start : void 0,
345
485
  spread: typeof e.attrs?.spread == "boolean" ? e.attrs.spread : void 0,
346
- children: (e.children ?? []).map(E)
486
+ children: (e.children ?? []).flatMap(G)
347
487
  };
348
488
  case "listItem": return {
349
489
  type: "listItem",
350
490
  checked: typeof e.attrs?.checked == "boolean" ? e.attrs.checked : null,
351
491
  spread: typeof e.attrs?.spread == "boolean" ? e.attrs.spread : void 0,
352
- children: (e.children ?? []).map(E)
492
+ children: (e.children ?? []).flatMap(G)
353
493
  };
354
494
  case "codeBlock": return {
355
495
  type: "code",
@@ -367,21 +507,21 @@ function E(e) {
367
507
  };
368
508
  case "emphasis": return {
369
509
  type: "emphasis",
370
- children: (e.children ?? []).map(E)
510
+ children: (e.children ?? []).flatMap(G)
371
511
  };
372
512
  case "strong": return {
373
513
  type: "strong",
374
- children: (e.children ?? []).map(E)
514
+ children: (e.children ?? []).flatMap(G)
375
515
  };
376
516
  case "strikethrough": return {
377
517
  type: "delete",
378
- children: (e.children ?? []).map(E)
518
+ children: (e.children ?? []).flatMap(G)
379
519
  };
380
520
  case "link": return {
381
521
  type: "link",
382
522
  url: typeof e.attrs?.url == "string" ? e.attrs.url : "",
383
523
  title: typeof e.attrs?.title == "string" ? e.attrs.title : null,
384
- children: (e.children ?? []).map(E)
524
+ children: (e.children ?? []).flatMap(G)
385
525
  };
386
526
  case "image": return {
387
527
  type: "image",
@@ -394,15 +534,15 @@ function E(e) {
394
534
  case "table": return {
395
535
  type: "table",
396
536
  align: Array.isArray(e.attrs?.align) ? e.attrs.align : void 0,
397
- children: (e.children ?? []).map(E)
537
+ children: (e.children ?? []).flatMap(G)
398
538
  };
399
539
  case "tableRow": return {
400
540
  type: "tableRow",
401
- children: (e.children ?? []).map(E)
541
+ children: (e.children ?? []).flatMap(G)
402
542
  };
403
543
  case "tableCell": return {
404
544
  type: "tableCell",
405
- children: (e.children ?? []).map(E)
545
+ children: (e.children ?? []).flatMap(G)
406
546
  };
407
547
  case "unsupported": return {
408
548
  type: "html",
@@ -414,14 +554,14 @@ function E(e) {
414
554
  };
415
555
  }
416
556
  }
417
- function D(e) {
557
+ function q(e) {
418
558
  let t = typeof e == "number" ? Math.trunc(e) : 1;
419
559
  return t <= 1 ? 1 : t === 2 ? 2 : t === 3 ? 3 : t === 4 ? 4 : t === 5 ? 5 : 6;
420
560
  }
421
561
  //#endregion
422
562
  //#region src/lib/transform.ts
423
- function O(e, ...t) {
563
+ function J(e, ...t) {
424
564
  return t.reduce((e, t) => t(e), e);
425
565
  }
426
566
  //#endregion
427
- export { s as createNodeId, o as hashStringFNV1a32, c as parse, w as serialize, O as transform };
567
+ export { s as createNodeId, o as hashStringFNV1a32, y as isColorSpanClose, S as parse, v as parseColorSpanOpen, m as sanitizeColor, h as sanitizeColorStyle, U as serialize, x as serializeColorSpanClose, b as serializeColorSpanOpen, J as transform };
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Sanitizer + tag helpers for inline color spans.
3
+ *
4
+ * Wire format on disk: `<span style="color: <value>">…</span>`. Whitelist
5
+ * approach — only `<span>` with a single `style="color: …"` declaration whose
6
+ * value matches one of the allowed CSS color forms is accepted. Anything else
7
+ * (extra attributes, multiple style declarations, `url(...)`, comments, etc.)
8
+ * is rejected; the parser then falls back to plain text.
9
+ *
10
+ * The same helpers run on both the viewer (during parse) and the editor
11
+ * (during paste / DOM-parse) so the two stay in lock-step on what counts as
12
+ * a valid color span.
13
+ */
14
+ /**
15
+ * Whitelist-validate a CSS color value. Returns the normalized value (trimmed,
16
+ * named colors lower-cased) when accepted, otherwise `null`.
17
+ *
18
+ * Rejected on principle:
19
+ * - Anything containing `;` (would smuggle in a second declaration)
20
+ * - Anything containing `/* … *\/` style comments
21
+ * - `url(...)`, `expression(...)`, `var(--…)` (intentional — use a hex or
22
+ * named color instead; `var()` would let consumers reach into arbitrary
23
+ * custom properties, defeating the whitelist)
24
+ * - Anything with `<` or `>` (HTML smuggling guard)
25
+ */
26
+ export declare function sanitizeColor(raw: string): string | null;
27
+ /**
28
+ * Inspect the raw `style` attribute value. Accepts only a single `color: <v>`
29
+ * declaration (with optional trailing semicolon) where `<v>` passes
30
+ * `sanitizeColor`. Returns the sanitized color on success, else `null`.
31
+ */
32
+ export declare function sanitizeColorStyle(rawStyle: string): string | null;
33
+ /**
34
+ * Try to parse a string like `<span style="color: red">` into `{ color }`.
35
+ * Returns `null` if anything other than a single `style` attribute appears,
36
+ * the style fails sanitization, or the tag isn't a `<span>`.
37
+ *
38
+ * Permissive on whitespace (`<span style = "color:red" >`), strict on
39
+ * structure: the only attribute allowed is `style`. No `class`, `id`,
40
+ * `data-*`, `on*` — anything beyond `style` rejects the whole tag.
41
+ */
42
+ export declare function parseColorSpanOpen(rawTag: string): {
43
+ color: string;
44
+ } | null;
45
+ /** Returns true iff the raw tag is a `</span>` close, ignoring whitespace. */
46
+ export declare function isColorSpanClose(rawTag: string): boolean;
47
+ /** Build the markdown wire form of an open color span tag. */
48
+ export declare function serializeColorSpanOpen(color: string): string;
49
+ /** The matching close tag — exposed for symmetry with the open helper. */
50
+ export declare function serializeColorSpanClose(): string;
51
+ //# sourceMappingURL=color-span.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"color-span.d.ts","sourceRoot":"","sources":["../../src/lib/color-span.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAiCH;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAiCxD;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAalE;AAOD;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAgB3E;AAED,8EAA8E;AAC9E,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAExD;AAED,8DAA8D;AAC9D,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE5D;AAED,0EAA0E;AAC1E,wBAAgB,uBAAuB,IAAI,MAAM,CAEhD"}
@@ -1 +1 @@
1
- {"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../src/lib/parse.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,gBAAgB,EAAkC,MAAM,SAAS,CAAC;AAGhF,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,wBAAgB,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,GAAE,oBAAyB,GAAG,gBAAgB,CAS5F"}
1
+ {"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../src/lib/parse.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,gBAAgB,EAAkC,MAAM,SAAS,CAAC;AAIhF,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,wBAAgB,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,GAAE,oBAAyB,GAAG,gBAAgB,CAS5F"}
@@ -1 +1 @@
1
- {"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../../src/lib/serialize.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAgB,MAAM,SAAS,CAAC;AAE9D,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,gBAAgB,EAAE,OAAO,GAAE,wBAA6B,GAAG,MAAM,CAS/F"}
1
+ {"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../../src/lib/serialize.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAgB,MAAM,SAAS,CAAC;AAG9D,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,gBAAgB,EAAE,OAAO,GAAE,wBAA6B,GAAG,MAAM,CAS/F"}
@@ -4,7 +4,7 @@ export interface MarkdownPosition {
4
4
  readonly line: number;
5
5
  readonly column: number;
6
6
  }
7
- export type MarkdownNodeType = 'heading' | 'paragraph' | 'blockquote' | 'list' | 'listItem' | 'codeBlock' | 'table' | 'tableRow' | 'tableCell' | 'thematicBreak' | 'lineBreak' | 'text' | 'emphasis' | 'strong' | 'strikethrough' | 'inlineCode' | 'link' | 'image' | 'unsupported';
7
+ export type MarkdownNodeType = 'heading' | 'paragraph' | 'blockquote' | 'list' | 'listItem' | 'codeBlock' | 'table' | 'tableRow' | 'tableCell' | 'thematicBreak' | 'lineBreak' | 'text' | 'emphasis' | 'strong' | 'strikethrough' | 'inlineCode' | 'link' | 'image' | 'colorSpan' | 'unsupported';
8
8
  export interface MarkdownNode {
9
9
  readonly id: string;
10
10
  readonly type: MarkdownNodeType | (string & {});
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,MAAM,gBAAgB,GACxB,SAAS,GACT,WAAW,GACX,YAAY,GACZ,MAAM,GACN,UAAU,GACV,WAAW,GACX,OAAO,GACP,UAAU,GACV,WAAW,GACX,eAAe,GACf,WAAW,GACX,MAAM,GACN,UAAU,GACV,QAAQ,GACR,eAAe,GACf,YAAY,GACZ,MAAM,GACN,OAAO,GACP,aAAa,CAAC;AAElB,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,gBAAgB,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;IAChD,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,YAAY,EAAE,CAAC;IAC5C,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACnD,QAAQ,CAAC,QAAQ,CAAC,EAAE,gBAAgB,CAAC;CACtC;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,KAAK,EAAE,SAAS,YAAY,EAAE,CAAC;IACxC,QAAQ,CAAC,IAAI,CAAC,EAAE;QACd,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;KAC9B,CAAC;CACH;AAED,MAAM,MAAM,iBAAiB,GAAG,CAAC,GAAG,EAAE,gBAAgB,KAAK,gBAAgB,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,MAAM,gBAAgB,GACxB,SAAS,GACT,WAAW,GACX,YAAY,GACZ,MAAM,GACN,UAAU,GACV,WAAW,GACX,OAAO,GACP,UAAU,GACV,WAAW,GACX,eAAe,GACf,WAAW,GACX,MAAM,GACN,UAAU,GACV,QAAQ,GACR,eAAe,GACf,YAAY,GACZ,MAAM,GACN,OAAO,GACP,WAAW,GACX,aAAa,CAAC;AAElB,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,gBAAgB,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;IAChD,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,YAAY,EAAE,CAAC;IAC5C,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACnD,QAAQ,CAAC,QAAQ,CAAC,EAAE,gBAAgB,CAAC;CACtC;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,KAAK,EAAE,SAAS,YAAY,EAAE,CAAC;IACxC,QAAQ,CAAC,IAAI,CAAC,EAAE;QACd,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;KAC9B,CAAC;CACH;AAED,MAAM,MAAM,iBAAiB,GAAG,CAAC,GAAG,EAAE,gBAAgB,KAAK,gBAAgB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocoar/vue-markdown-core",
3
- "version": "1.14.0",
3
+ "version": "1.16.0",
4
4
  "description": "Core markdown parsing utilities for @cocoar/vue-markdown",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {