@cocoar/vue-markdown-core 2.11.0 → 2.12.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 +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +150 -50
- package/dist/lib/embed-directive.d.ts +48 -0
- package/dist/lib/embed-directive.d.ts.map +1 -0
- package/dist/lib/parse.d.ts.map +1 -1
- package/dist/lib/serialize.d.ts.map +1 -1
- package/dist/lib/types.d.ts +1 -1
- package/dist/lib/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4260,43 +4260,130 @@ function Zr() {
|
|
|
4260
4260
|
return "</span>";
|
|
4261
4261
|
}
|
|
4262
4262
|
//#endregion
|
|
4263
|
+
//#region src/lib/embed-directive.ts
|
|
4264
|
+
var Qr = /^:::([A-Za-z][A-Za-z0-9_-]*)[ \t]*(?:\{([\s\S]*)\})?[ \t]*$/, $r = /^[A-Za-z0-9_./:%+#-]+$/;
|
|
4265
|
+
function ei(e) {
|
|
4266
|
+
let t = Qr.exec(e);
|
|
4267
|
+
if (!t) return null;
|
|
4268
|
+
let n = t[1], r = t[2];
|
|
4269
|
+
return {
|
|
4270
|
+
key: n,
|
|
4271
|
+
props: r === void 0 ? {} : ri(r)
|
|
4272
|
+
};
|
|
4273
|
+
}
|
|
4274
|
+
function ti(e) {
|
|
4275
|
+
return `:::${e.key}${ii(e.props)}`;
|
|
4276
|
+
}
|
|
4277
|
+
function ni(e) {
|
|
4278
|
+
return e === " " || e === " " || e === "\n" || e === "\r";
|
|
4279
|
+
}
|
|
4280
|
+
function ri(e) {
|
|
4281
|
+
let t = {}, n = 0, r = e.length;
|
|
4282
|
+
for (; n < r;) {
|
|
4283
|
+
for (; n < r && ni(e[n]);) n++;
|
|
4284
|
+
if (n >= r) break;
|
|
4285
|
+
let i = n;
|
|
4286
|
+
for (; n < r && !ni(e[n]) && e[n] !== "=";) n++;
|
|
4287
|
+
let a = e.slice(i, n);
|
|
4288
|
+
if (a.length === 0) {
|
|
4289
|
+
n++;
|
|
4290
|
+
continue;
|
|
4291
|
+
}
|
|
4292
|
+
if (n < r && e[n] === "=") {
|
|
4293
|
+
n++;
|
|
4294
|
+
let i, o = e[n];
|
|
4295
|
+
if (o === "\"" || o === "'") {
|
|
4296
|
+
n++;
|
|
4297
|
+
let t = "";
|
|
4298
|
+
for (; n < r && e[n] !== o;) e[n] === "\\" && n + 1 < r ? (t += e[n + 1], n += 2) : (t += e[n], n++);
|
|
4299
|
+
n++, i = t;
|
|
4300
|
+
} else {
|
|
4301
|
+
let t = n;
|
|
4302
|
+
for (; n < r && !ni(e[n]);) n++;
|
|
4303
|
+
i = e.slice(t, n);
|
|
4304
|
+
}
|
|
4305
|
+
t[a] = i;
|
|
4306
|
+
} else t[a] = "";
|
|
4307
|
+
}
|
|
4308
|
+
return t;
|
|
4309
|
+
}
|
|
4310
|
+
function ii(e) {
|
|
4311
|
+
let t = [];
|
|
4312
|
+
for (let [n, r] of Object.entries(e)) r === "" ? t.push(n) : $r.test(r) ? t.push(`${n}=${r}`) : t.push(`${n}=${ai(r)}`);
|
|
4313
|
+
return t.length > 0 ? `{${t.join(" ")}}` : "";
|
|
4314
|
+
}
|
|
4315
|
+
function ai(e) {
|
|
4316
|
+
return `"${e.replace(/\\/g, "\\\\").replace(/"/g, "\\\"")}"`;
|
|
4317
|
+
}
|
|
4318
|
+
function oi(e) {
|
|
4319
|
+
if (!e || typeof e != "object") return {};
|
|
4320
|
+
let t = {};
|
|
4321
|
+
for (let [n, r] of Object.entries(e)) typeof r == "string" && (t[n] = r);
|
|
4322
|
+
return t;
|
|
4323
|
+
}
|
|
4324
|
+
//#endregion
|
|
4263
4325
|
//#region src/lib/parse.ts
|
|
4264
|
-
function
|
|
4326
|
+
function si(r, i = {}) {
|
|
4265
4327
|
let a = e().use(t);
|
|
4266
|
-
return (i.gfm ?? !0) && a.use(n), a.use(Nr, ["yaml"]),
|
|
4328
|
+
return (i.gfm ?? !0) && a.use(n), a.use(Nr, ["yaml"]), ci(a.parse(r), r);
|
|
4267
4329
|
}
|
|
4268
|
-
function
|
|
4269
|
-
let
|
|
4270
|
-
return { nodes:
|
|
4330
|
+
function ci(e, t) {
|
|
4331
|
+
let n = wi(), r = gi(e);
|
|
4332
|
+
return { nodes: li(di(e.children.map((e, t) => Q(e, void 0, t, n, r)).filter(Z)), t) };
|
|
4271
4333
|
}
|
|
4272
|
-
function
|
|
4273
|
-
return
|
|
4334
|
+
function li(e, t) {
|
|
4335
|
+
return e.map((e) => {
|
|
4336
|
+
let n = ui(e, t);
|
|
4337
|
+
if (n) return n;
|
|
4274
4338
|
if (!e.children) return e;
|
|
4275
|
-
let
|
|
4276
|
-
return
|
|
4339
|
+
let r = li(e.children, t);
|
|
4340
|
+
return fi(e.children, r) ? e : {
|
|
4341
|
+
...e,
|
|
4342
|
+
children: r
|
|
4343
|
+
};
|
|
4344
|
+
});
|
|
4345
|
+
}
|
|
4346
|
+
function ui(e, t) {
|
|
4347
|
+
if (e.type !== "paragraph" || !e.position) return null;
|
|
4348
|
+
let n = ei(t.slice(e.position.start, e.position.end).trim());
|
|
4349
|
+
return n ? {
|
|
4350
|
+
id: Lr(`embed|${e.id}`),
|
|
4351
|
+
type: "embed",
|
|
4352
|
+
position: e.position,
|
|
4353
|
+
attrs: {
|
|
4354
|
+
key: n.key,
|
|
4355
|
+
props: n.props
|
|
4356
|
+
}
|
|
4357
|
+
} : null;
|
|
4358
|
+
}
|
|
4359
|
+
function di(e) {
|
|
4360
|
+
return mi(e.map((e) => {
|
|
4361
|
+
if (!e.children) return e;
|
|
4362
|
+
let t = di(e.children);
|
|
4363
|
+
return fi(e.children, t) ? e : {
|
|
4277
4364
|
...e,
|
|
4278
4365
|
children: t
|
|
4279
4366
|
};
|
|
4280
4367
|
}));
|
|
4281
4368
|
}
|
|
4282
|
-
function
|
|
4369
|
+
function fi(e, t) {
|
|
4283
4370
|
if (e.length !== t.length) return !1;
|
|
4284
4371
|
for (let n = 0; n < e.length; n++) if (e[n] !== t[n]) return !1;
|
|
4285
4372
|
return !0;
|
|
4286
4373
|
}
|
|
4287
|
-
function
|
|
4374
|
+
function pi(e) {
|
|
4288
4375
|
return e.type === "unsupported" && e.attrs?.originalType === "html" && typeof e.text == "string";
|
|
4289
4376
|
}
|
|
4290
|
-
function
|
|
4377
|
+
function mi(e) {
|
|
4291
4378
|
let t = [], n = 0;
|
|
4292
4379
|
for (; n < e.length;) {
|
|
4293
4380
|
let r = e[n];
|
|
4294
|
-
if (
|
|
4381
|
+
if (pi(r)) {
|
|
4295
4382
|
let i = Jr(r.text);
|
|
4296
4383
|
if (i) {
|
|
4297
|
-
let a =
|
|
4384
|
+
let a = hi(e, n);
|
|
4298
4385
|
if (a !== null) {
|
|
4299
|
-
let o =
|
|
4386
|
+
let o = mi(e.slice(n + 1, a)), s = e[a]?.position, c = r.position?.start, l = s?.end, u = typeof c == "number" && typeof l == "number" && r.position && s ? {
|
|
4300
4387
|
start: c,
|
|
4301
4388
|
end: l,
|
|
4302
4389
|
line: r.position.line,
|
|
@@ -4317,11 +4404,11 @@ function ri(e) {
|
|
|
4317
4404
|
}
|
|
4318
4405
|
return t;
|
|
4319
4406
|
}
|
|
4320
|
-
function
|
|
4407
|
+
function hi(e, t) {
|
|
4321
4408
|
let n = 1;
|
|
4322
4409
|
for (let r = t + 1; r < e.length; r++) {
|
|
4323
4410
|
let t = e[r];
|
|
4324
|
-
if (
|
|
4411
|
+
if (pi(t)) {
|
|
4325
4412
|
if (Jr(t.text)) {
|
|
4326
4413
|
n++;
|
|
4327
4414
|
continue;
|
|
@@ -4331,7 +4418,7 @@ function ii(e, t) {
|
|
|
4331
4418
|
}
|
|
4332
4419
|
return null;
|
|
4333
4420
|
}
|
|
4334
|
-
function
|
|
4421
|
+
function gi(e) {
|
|
4335
4422
|
let t = /* @__PURE__ */ new Map();
|
|
4336
4423
|
for (let n of e.children) {
|
|
4337
4424
|
if (n.type !== "definition") continue;
|
|
@@ -4347,7 +4434,7 @@ function Z(e) {
|
|
|
4347
4434
|
return e !== null;
|
|
4348
4435
|
}
|
|
4349
4436
|
function Q(e, t, n, r, i) {
|
|
4350
|
-
let a =
|
|
4437
|
+
let a = Di(e.position), o = `${e.type}|${a?.start ?? "na"}-${a?.end ?? "na"}|${t ?? "root"}|${n}`, s = Lr(o);
|
|
4351
4438
|
if (e.type === "yaml") {
|
|
4352
4439
|
let t = typeof e.value == "string" ? e.value : "", { data: n, entries: r } = lr(t);
|
|
4353
4440
|
return {
|
|
@@ -4362,7 +4449,7 @@ function Q(e, t, n, r, i) {
|
|
|
4362
4449
|
};
|
|
4363
4450
|
}
|
|
4364
4451
|
switch (e.type) {
|
|
4365
|
-
case "heading": return
|
|
4452
|
+
case "heading": return _i(e, s, a, r, i);
|
|
4366
4453
|
case "paragraph": return {
|
|
4367
4454
|
id: s,
|
|
4368
4455
|
type: "paragraph",
|
|
@@ -4375,8 +4462,8 @@ function Q(e, t, n, r, i) {
|
|
|
4375
4462
|
position: a,
|
|
4376
4463
|
children: (e.children ?? []).map((e, t) => Q(e, s, t, r, i)).filter(Z)
|
|
4377
4464
|
};
|
|
4378
|
-
case "list": return
|
|
4379
|
-
case "listItem": return
|
|
4465
|
+
case "list": return yi(e, s, a, r, i);
|
|
4466
|
+
case "listItem": return bi(e, s, a, r, i);
|
|
4380
4467
|
case "code": return {
|
|
4381
4468
|
id: s,
|
|
4382
4469
|
type: "codeBlock",
|
|
@@ -4422,14 +4509,14 @@ function Q(e, t, n, r, i) {
|
|
|
4422
4509
|
position: a,
|
|
4423
4510
|
children: (e.children ?? []).map((e, t) => Q(e, s, t, r, i)).filter(Z)
|
|
4424
4511
|
};
|
|
4425
|
-
case "link": return
|
|
4512
|
+
case "link": return vi(e, s, a, r, i);
|
|
4426
4513
|
case "linkReference": {
|
|
4427
4514
|
let t = e, n = typeof t.identifier == "string" ? t.identifier : "", o = n.length > 0 ? i.get(n) : void 0;
|
|
4428
4515
|
if (!o?.url) return {
|
|
4429
4516
|
id: s,
|
|
4430
4517
|
type: "text",
|
|
4431
4518
|
position: a,
|
|
4432
|
-
text:
|
|
4519
|
+
text: Ei(e)
|
|
4433
4520
|
};
|
|
4434
4521
|
let c = Array.isArray(t.children) ? t.children : [];
|
|
4435
4522
|
return {
|
|
@@ -4484,9 +4571,9 @@ function Q(e, t, n, r, i) {
|
|
|
4484
4571
|
type: "thematicBreak",
|
|
4485
4572
|
position: a
|
|
4486
4573
|
};
|
|
4487
|
-
case "table": return
|
|
4488
|
-
case "tableRow": return
|
|
4489
|
-
case "tableCell": return
|
|
4574
|
+
case "table": return xi(e, s, a, r, i);
|
|
4575
|
+
case "tableRow": return Si(e, s, a, r, i);
|
|
4576
|
+
case "tableCell": return Ci(e, s, a, r, i);
|
|
4490
4577
|
case "definition": return null;
|
|
4491
4578
|
case "footnoteReference": {
|
|
4492
4579
|
let t = e, n = typeof t.identifier == "string" ? t.identifier : typeof t.label == "string" ? t.label : "";
|
|
@@ -4531,8 +4618,8 @@ function Q(e, t, n, r, i) {
|
|
|
4531
4618
|
};
|
|
4532
4619
|
}
|
|
4533
4620
|
}
|
|
4534
|
-
function
|
|
4535
|
-
let a =
|
|
4621
|
+
function _i(e, t, n, r, i) {
|
|
4622
|
+
let a = Ei(e), o = a.length > 0 ? r.slug(a) : void 0;
|
|
4536
4623
|
return {
|
|
4537
4624
|
id: t,
|
|
4538
4625
|
type: "heading",
|
|
@@ -4544,7 +4631,7 @@ function oi(e, t, n, r, i) {
|
|
|
4544
4631
|
children: (e.children ?? []).map((e, n) => Q(e, t, n, r, i)).filter(Z)
|
|
4545
4632
|
};
|
|
4546
4633
|
}
|
|
4547
|
-
function
|
|
4634
|
+
function vi(e, t, n, r, i) {
|
|
4548
4635
|
return {
|
|
4549
4636
|
id: t,
|
|
4550
4637
|
type: "link",
|
|
@@ -4556,7 +4643,7 @@ function si(e, t, n, r, i) {
|
|
|
4556
4643
|
children: (e.children ?? []).map((e, n) => Q(e, t, n, r, i)).filter(Z)
|
|
4557
4644
|
};
|
|
4558
4645
|
}
|
|
4559
|
-
function
|
|
4646
|
+
function yi(e, t, n, r, i) {
|
|
4560
4647
|
return {
|
|
4561
4648
|
id: t,
|
|
4562
4649
|
type: "list",
|
|
@@ -4569,7 +4656,7 @@ function ci(e, t, n, r, i) {
|
|
|
4569
4656
|
children: (e.children ?? []).map((e, n) => Q(e, t, n, r, i)).filter(Z)
|
|
4570
4657
|
};
|
|
4571
4658
|
}
|
|
4572
|
-
function
|
|
4659
|
+
function bi(e, t, n, r, i) {
|
|
4573
4660
|
return {
|
|
4574
4661
|
id: t,
|
|
4575
4662
|
type: "listItem",
|
|
@@ -4581,7 +4668,7 @@ function li(e, t, n, r, i) {
|
|
|
4581
4668
|
children: (e.children ?? []).map((e, n) => Q(e, t, n, r, i)).filter(Z)
|
|
4582
4669
|
};
|
|
4583
4670
|
}
|
|
4584
|
-
function
|
|
4671
|
+
function xi(e, t, n, r, i) {
|
|
4585
4672
|
return {
|
|
4586
4673
|
id: t,
|
|
4587
4674
|
type: "table",
|
|
@@ -4590,7 +4677,7 @@ function ui(e, t, n, r, i) {
|
|
|
4590
4677
|
children: (e.children ?? []).map((e, n) => Q(e, t, n, r, i)).filter(Z)
|
|
4591
4678
|
};
|
|
4592
4679
|
}
|
|
4593
|
-
function
|
|
4680
|
+
function Si(e, t, n, r, i) {
|
|
4594
4681
|
return {
|
|
4595
4682
|
id: t,
|
|
4596
4683
|
type: "tableRow",
|
|
@@ -4598,7 +4685,7 @@ function di(e, t, n, r, i) {
|
|
|
4598
4685
|
children: (e.children ?? []).map((e, n) => Q(e, t, n, r, i)).filter(Z)
|
|
4599
4686
|
};
|
|
4600
4687
|
}
|
|
4601
|
-
function
|
|
4688
|
+
function Ci(e, t, n, r, i) {
|
|
4602
4689
|
return {
|
|
4603
4690
|
id: t,
|
|
4604
4691
|
type: "tableCell",
|
|
@@ -4606,23 +4693,23 @@ function fi(e, t, n, r, i) {
|
|
|
4606
4693
|
children: (e.children ?? []).map((e, n) => Q(e, t, n, r, i)).filter(Z)
|
|
4607
4694
|
};
|
|
4608
4695
|
}
|
|
4609
|
-
function
|
|
4696
|
+
function wi() {
|
|
4610
4697
|
let e = /* @__PURE__ */ new Map();
|
|
4611
4698
|
return { slug(t) {
|
|
4612
|
-
let n =
|
|
4699
|
+
let n = Ti(t), r = e.get(n) ?? 0;
|
|
4613
4700
|
return e.set(n, r + 1), r === 0 ? n : `${n}-${r}`;
|
|
4614
4701
|
} };
|
|
4615
4702
|
}
|
|
4616
|
-
function
|
|
4703
|
+
function Ti(e) {
|
|
4617
4704
|
let t = e.trim().toLowerCase().replace(/[^\p{L}\p{N}\s-]+/gu, "").replace(/\s+/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
|
|
4618
4705
|
return t.length > 0 ? t : "section";
|
|
4619
4706
|
}
|
|
4620
|
-
function
|
|
4707
|
+
function Ei(e) {
|
|
4621
4708
|
if (!e || typeof e != "object") return "";
|
|
4622
4709
|
let t = e;
|
|
4623
|
-
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) =>
|
|
4710
|
+
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) => Ei(e)).join("") : "";
|
|
4624
4711
|
}
|
|
4625
|
-
function
|
|
4712
|
+
function Di(e) {
|
|
4626
4713
|
let t = e;
|
|
4627
4714
|
if (!t?.start || !t?.end) return;
|
|
4628
4715
|
let n = t.start.offset, r = t.end.offset, i = t.start.line, a = t.start.column;
|
|
@@ -4635,11 +4722,11 @@ function gi(e) {
|
|
|
4635
4722
|
}
|
|
4636
4723
|
//#endregion
|
|
4637
4724
|
//#region src/lib/serialize.ts
|
|
4638
|
-
function
|
|
4639
|
-
let a =
|
|
4725
|
+
function Oi(t, i = {}) {
|
|
4726
|
+
let a = ki(t), o = e().use(r);
|
|
4640
4727
|
return (i.gfm ?? !0) && o.use(n), o.use(Nr, ["yaml"]), String(o.stringify(a));
|
|
4641
4728
|
}
|
|
4642
|
-
function
|
|
4729
|
+
function ki(e) {
|
|
4643
4730
|
return {
|
|
4644
4731
|
type: "root",
|
|
4645
4732
|
children: e.nodes.flatMap((e) => $(e))
|
|
@@ -4660,9 +4747,9 @@ function $(e) {
|
|
|
4660
4747
|
}
|
|
4661
4748
|
] : (e.children ?? []).flatMap($);
|
|
4662
4749
|
}
|
|
4663
|
-
return [
|
|
4750
|
+
return [Ai(e)];
|
|
4664
4751
|
}
|
|
4665
|
-
function
|
|
4752
|
+
function Ai(e) {
|
|
4666
4753
|
switch (e.type) {
|
|
4667
4754
|
case "frontmatter": return {
|
|
4668
4755
|
type: "yaml",
|
|
@@ -4670,7 +4757,7 @@ function yi(e) {
|
|
|
4670
4757
|
};
|
|
4671
4758
|
case "heading": return {
|
|
4672
4759
|
type: "heading",
|
|
4673
|
-
depth:
|
|
4760
|
+
depth: ji(e.attrs?.depth),
|
|
4674
4761
|
children: (e.children ?? []).flatMap($)
|
|
4675
4762
|
};
|
|
4676
4763
|
case "paragraph": return {
|
|
@@ -4747,6 +4834,19 @@ function yi(e) {
|
|
|
4747
4834
|
type: "tableCell",
|
|
4748
4835
|
children: (e.children ?? []).flatMap($)
|
|
4749
4836
|
};
|
|
4837
|
+
case "embed": {
|
|
4838
|
+
let t = typeof e.attrs?.key == "string" ? e.attrs.key : "";
|
|
4839
|
+
return t.length === 0 ? {
|
|
4840
|
+
type: "html",
|
|
4841
|
+
value: ""
|
|
4842
|
+
} : {
|
|
4843
|
+
type: "html",
|
|
4844
|
+
value: ti({
|
|
4845
|
+
key: t,
|
|
4846
|
+
props: oi(e.attrs?.props)
|
|
4847
|
+
})
|
|
4848
|
+
};
|
|
4849
|
+
}
|
|
4750
4850
|
case "unsupported": return {
|
|
4751
4851
|
type: "html",
|
|
4752
4852
|
value: `<!-- Unsupported node: ${String(e.attrs?.originalType ?? "unknown")} -->`
|
|
@@ -4757,14 +4857,14 @@ function yi(e) {
|
|
|
4757
4857
|
};
|
|
4758
4858
|
}
|
|
4759
4859
|
}
|
|
4760
|
-
function
|
|
4860
|
+
function ji(e) {
|
|
4761
4861
|
let t = typeof e == "number" ? Math.trunc(e) : 1;
|
|
4762
4862
|
return t <= 1 ? 1 : t === 2 ? 2 : t === 3 ? 3 : t === 4 ? 4 : t === 5 ? 5 : 6;
|
|
4763
4863
|
}
|
|
4764
4864
|
//#endregion
|
|
4765
4865
|
//#region src/lib/transform.ts
|
|
4766
|
-
function
|
|
4866
|
+
function Mi(e, ...t) {
|
|
4767
4867
|
return t.reduce((e, t) => t(e), e);
|
|
4768
4868
|
}
|
|
4769
4869
|
//#endregion
|
|
4770
|
-
export { Lr as createNodeId, Ir as hashStringFNV1a32, Yr as isColorSpanClose,
|
|
4870
|
+
export { Lr as createNodeId, Ir as hashStringFNV1a32, Yr as isColorSpanClose, si as parse, Jr as parseColorSpanOpen, ei as parseEmbedDirective, lr as parseFrontmatter, Wr as sanitizeColor, Gr as sanitizeColorStyle, Oi as serialize, Zr as serializeColorSpanClose, Xr as serializeColorSpanOpen, ti as serializeEmbedDirective, oi as toEmbedProps, Mi as transform };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parser + serializer for generic custom-embed directives.
|
|
3
|
+
*
|
|
4
|
+
* Wire format on disk: a standalone block on its own line —
|
|
5
|
+
*
|
|
6
|
+
* :::key{attr=value attr2="quoted value" flag}
|
|
7
|
+
*
|
|
8
|
+
* `key` selects a registered embed component (the registry lives in the Vue
|
|
9
|
+
* layer, `@cocoar/vue-markdown`); the attributes become the `props` handed to
|
|
10
|
+
* that component verbatim. The parser here is intentionally **embed-agnostic**:
|
|
11
|
+
* it turns *any* `:::key{…}` into a `{ key, props }` pair and never consults a
|
|
12
|
+
* registry. Lookup happens only at render / edit time. Unknown keys still parse
|
|
13
|
+
* and round-trip losslessly.
|
|
14
|
+
*
|
|
15
|
+
* Why a hand-rolled parser instead of `remark-directive`: it matches the house
|
|
16
|
+
* style (color spans are folded the same way), gives us byte-stable round-trip
|
|
17
|
+
* of the exact single-line form, and avoids remark-directive's container
|
|
18
|
+
* semantics where `:::name` with no closing fence swallows following content.
|
|
19
|
+
*
|
|
20
|
+
* Attribute values are plain strings by source form. Any richer typing /
|
|
21
|
+
* coercion is the registered component's concern. Untrusted author text in an
|
|
22
|
+
* attribute value is safe here because the value is never interpolated into
|
|
23
|
+
* HTML — the Vue renderer binds it as a prop, not via `innerHTML`.
|
|
24
|
+
*/
|
|
25
|
+
export interface EmbedDirective {
|
|
26
|
+
/** The embed key (the bit right after `:::`). */
|
|
27
|
+
readonly key: string;
|
|
28
|
+
/** Attribute map. Valueless attributes (`flag`) map to an empty string. */
|
|
29
|
+
readonly props: Readonly<Record<string, string>>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Parse a single line into an {@link EmbedDirective}, or `null` when the line
|
|
33
|
+
* is not an embed directive. The caller is expected to pass a trimmed line.
|
|
34
|
+
*/
|
|
35
|
+
export declare function parseEmbedDirective(line: string): EmbedDirective | null;
|
|
36
|
+
/**
|
|
37
|
+
* Serialize an {@link EmbedDirective} back to its canonical single-line form.
|
|
38
|
+
* Round-trips `parseEmbedDirective` for the canonical form; non-canonical input
|
|
39
|
+
* (extra spaces, redundant quoting) is normalized but stays semantically equal.
|
|
40
|
+
*/
|
|
41
|
+
export declare function serializeEmbedDirective(directive: EmbedDirective): string;
|
|
42
|
+
/**
|
|
43
|
+
* Coerce an unknown `attrs.props` value into a clean `Record<string, string>`,
|
|
44
|
+
* dropping any non-string entries. Used by the serializer, which receives the
|
|
45
|
+
* loosely-typed `MarkdownNode.attrs`.
|
|
46
|
+
*/
|
|
47
|
+
export declare function toEmbedProps(value: unknown): Record<string, string>;
|
|
48
|
+
//# sourceMappingURL=embed-directive.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embed-directive.d.ts","sourceRoot":"","sources":["../../src/lib/embed-directive.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,MAAM,WAAW,cAAc;IAC7B,iDAAiD;IACjD,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,2EAA2E;IAC3E,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CAClD;AAgBD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI,CAQvE;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,cAAc,GAAG,MAAM,CAEzE;AA+ED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAOnE"}
|
package/dist/lib/parse.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../src/lib/parse.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,gBAAgB,EAAkC,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../src/lib/parse.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,gBAAgB,EAAkC,MAAM,SAAS,CAAC;AAMhF,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,CAc5F"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../../src/lib/serialize.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,gBAAgB,EAAgB,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../../src/lib/serialize.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,gBAAgB,EAAgB,MAAM,SAAS,CAAC;AAI9D,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,CAa/F"}
|
package/dist/lib/types.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export interface MarkdownPosition {
|
|
|
4
4
|
readonly line: number;
|
|
5
5
|
readonly column: number;
|
|
6
6
|
}
|
|
7
|
-
export type MarkdownNodeType = 'frontmatter' | 'heading' | 'paragraph' | 'blockquote' | 'list' | 'listItem' | 'codeBlock' | 'table' | 'tableRow' | 'tableCell' | 'thematicBreak' | 'lineBreak' | 'text' | 'emphasis' | 'strong' | 'strikethrough' | 'inlineCode' | 'link' | 'image' | 'colorSpan' | 'unsupported';
|
|
7
|
+
export type MarkdownNodeType = 'frontmatter' | 'heading' | 'paragraph' | 'blockquote' | 'list' | 'listItem' | 'codeBlock' | 'table' | 'tableRow' | 'tableCell' | 'thematicBreak' | 'lineBreak' | 'text' | 'emphasis' | 'strong' | 'strikethrough' | 'inlineCode' | 'link' | 'image' | 'colorSpan' | 'embed' | 'unsupported';
|
|
8
8
|
export interface MarkdownNode {
|
|
9
9
|
readonly id: string;
|
|
10
10
|
readonly type: MarkdownNodeType | (string & {});
|
package/dist/lib/types.d.ts.map
CHANGED
|
@@ -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,aAAa,GACb,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"}
|
|
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,aAAa,GACb,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,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"}
|