@blogmcp/sdk 0.2.2 → 0.3.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.
@@ -1,70 +1,74 @@
1
- const f = /<[A-Z][a-zA-Z]*[\s/>]/, u = /<([A-Z][a-zA-Z]*)\s*([^>]*)>([\s\S]*?)<\/\1>|<([A-Z][a-zA-Z]*)\s*((?:[^/]|\/(?!>))*)\/>/g;
2
- function p(n, i) {
3
- if (n[i] !== "{")
1
+ const d = /<[A-Z][a-zA-Z]*[\s/>]/, A = /<([A-Z][a-zA-Z]*)\s*([^>]*)>([\s\S]*?)<\/\1>|<([A-Z][a-zA-Z]*)\s*((?:[^/]|\/(?!>))*)\/>/g;
2
+ function g(t, i) {
3
+ if (t[i] !== "{")
4
4
  return null;
5
- let e = 0, t = null;
6
- for (let s = i; s < n.length; s++) {
7
- const r = n[s];
8
- if (t) {
9
- if (r === "\\") {
10
- s++;
5
+ let e = 0, n = null;
6
+ for (let u = i; u < t.length; u++) {
7
+ const s = t[u];
8
+ if (n) {
9
+ if (s === "\\") {
10
+ u++;
11
11
  continue;
12
12
  }
13
- r === t && (t = null);
13
+ s === n && (n = null);
14
14
  continue;
15
15
  }
16
- if (r === '"' || r === "'") {
17
- t = r;
16
+ if (s === '"' || s === "'") {
17
+ n = s;
18
18
  continue;
19
19
  }
20
- if (r === "{") {
20
+ if (s === "{") {
21
21
  e++;
22
22
  continue;
23
23
  }
24
- if (r === "}" && (e--, e === 0))
25
- return { content: n.slice(i + 1, s), endIndex: s + 1 };
24
+ if (s === "}" && (e--, e === 0))
25
+ return { content: t.slice(i + 1, u), endIndex: u + 1 };
26
26
  }
27
27
  return null;
28
28
  }
29
- function h(n) {
29
+ function x(t) {
30
30
  const i = {};
31
- if (!n.trim())
31
+ if (!t.trim())
32
32
  return i;
33
33
  let e = 0;
34
- const t = n;
35
- for (; e < t.length; ) {
36
- for (; e < t.length && /\s/.test(t[e]); )
34
+ const n = t;
35
+ for (; e < n.length; ) {
36
+ for (; e < n.length && /\s/.test(n[e]); )
37
37
  e++;
38
- if (e >= t.length)
38
+ if (e >= n.length)
39
39
  break;
40
- const s = t.slice(e).match(/^(\w+)/);
41
- if (!s) {
40
+ const u = n.slice(e).match(/^(\w+)/);
41
+ if (!u) {
42
42
  e++;
43
43
  continue;
44
44
  }
45
- const r = s[1];
46
- for (e += r.length; e < t.length && /\s/.test(t[e]); )
45
+ const s = u[1];
46
+ for (e += s.length; e < n.length && /\s/.test(n[e]); )
47
47
  e++;
48
- if (t[e] !== "=") {
49
- i[r] = !0;
48
+ if (n[e] !== "=") {
49
+ i[s] = !0;
50
50
  continue;
51
51
  }
52
- for (e++; e < t.length && /\s/.test(t[e]); )
52
+ for (e++; e < n.length && /\s/.test(n[e]); )
53
53
  e++;
54
- if (t[e] === '"') {
55
- const l = t.indexOf('"', e + 1);
54
+ if (n[e] === '"') {
55
+ const l = n.indexOf('"', e + 1);
56
56
  if (l === -1) {
57
- i[r] = "";
57
+ i[s] = "";
58
58
  break;
59
59
  }
60
- i[r] = t.slice(e + 1, l), e = l + 1;
61
- } else if (t[e] === "{") {
62
- const l = p(t, e);
60
+ i[s] = n.slice(e + 1, l), e = l + 1;
61
+ } else if (n[e] === "{") {
62
+ const l = g(n, e);
63
63
  if (l) {
64
64
  try {
65
- i[r] = JSON.parse(l.content.replace(/'/g, '"'));
65
+ i[s] = JSON.parse(l.content);
66
66
  } catch {
67
- i[r] = l.content;
67
+ try {
68
+ i[s] = JSON.parse(l.content.replace(/'/g, '"'));
69
+ } catch {
70
+ i[s] = l.content;
71
+ }
68
72
  }
69
73
  e = l.endIndex;
70
74
  } else
@@ -74,66 +78,312 @@ function h(n) {
74
78
  }
75
79
  return i;
76
80
  }
77
- function a(n) {
81
+ function O(t) {
78
82
  const i = [];
79
- for (const [e, t] of Object.entries(n))
80
- t != null && (t === !0 ? i.push(e) : typeof t == "string" ? i.push(`${e}="${t}"`) : typeof t == "number" ? i.push(`${e}={${t}}`) : typeof t == "boolean" ? i.push(`${e}={${t}}`) : i.push(`${e}={${JSON.stringify(t)}}`));
83
+ for (const [e, n] of Object.entries(t))
84
+ n != null && (n === !0 ? i.push(e) : typeof n == "string" ? i.push(n.includes('"') ? `${e}={${JSON.stringify(n)}}` : `${e}="${n}"`) : typeof n == "number" ? i.push(`${e}={${n}}`) : typeof n == "boolean" ? i.push(`${e}={${n}}`) : i.push(`${e}={${JSON.stringify(n)}}`));
81
85
  return i.join(" ");
82
86
  }
83
- function m(n, i, e) {
84
- const t = a(i), s = t ? ` ${t}` : "";
85
- return e ? `<${n}${s}>
87
+ function b(t, i, e) {
88
+ const n = O(i), u = n ? ` ${n}` : "";
89
+ return e ? `<${t}${u}>
86
90
  ${e}
87
- </${n}>` : `<${n}${s} />`;
91
+ </${t}>` : `<${t}${u} />`;
88
92
  }
89
- function d(n) {
90
- if (n.startsWith("---")) {
91
- const i = n.indexOf("---", 3);
93
+ function _(t) {
94
+ if (t.startsWith("---")) {
95
+ const i = t.indexOf("---", 3);
92
96
  if (i !== -1)
93
- return n.substring(i + 3).trim();
97
+ return t.substring(i + 3).trim();
94
98
  }
95
- return n;
99
+ return t;
96
100
  }
97
- function g(n) {
98
- if (n.startsWith("---")) {
99
- const i = n.indexOf("---", 3);
101
+ function Z(t) {
102
+ if (t.startsWith("---")) {
103
+ const i = t.indexOf("---", 3);
100
104
  if (i !== -1)
101
- return n.substring(3, i).trim();
105
+ return t.substring(3, i).trim();
102
106
  }
103
107
  return null;
104
108
  }
105
- function x(n) {
106
- if (!f.test(n))
107
- return [{ type: "html", content: n }];
108
- const i = new RegExp(u.source, "g"), e = [];
109
- let t = 0, s;
110
- for (; (s = i.exec(n)) !== null; ) {
111
- if (s.index > t) {
112
- const o = n.slice(t, s.index);
113
- o.trim() && e.push({ type: "html", content: o });
114
- }
115
- const r = s[1] || s[4] || "", l = s[1] ? s[2] || "" : s[5] || "", c = s[3];
109
+ function M(t) {
110
+ if (!t || !t.startsWith("---"))
111
+ return 0;
112
+ const i = t.indexOf("---", 3);
113
+ if (i === -1)
114
+ return 0;
115
+ const e = i + 3, n = t.slice(e);
116
+ return e + (n.length - n.trimStart().length);
117
+ }
118
+ function z(t, i) {
119
+ if (i <= 0)
120
+ return 1;
121
+ const e = Math.min(i, t.length);
122
+ let n = 1;
123
+ for (let u = 0; u < e; u++)
124
+ t[u] === `
125
+ ` && n++;
126
+ return n;
127
+ }
128
+ const m = 0, E = 1, w = 2, y = /^ {0,3}(`{3,}|~{3,})(.*)$/, S = /^ {0,3}(`{3,}|~{3,})[ \t]*$/;
129
+ function $(t) {
130
+ const i = new Uint8Array(t.length);
131
+ if (!t || !t.includes("`") && !t.includes("~"))
132
+ return i;
133
+ const e = [], n = [];
134
+ for (let l = 0; l <= t.length; ) {
135
+ const o = t.indexOf(`
136
+ `, l);
137
+ if (e.push(l), n.push(o === -1 ? t.length : o), o === -1)
138
+ break;
139
+ l = o + 1;
140
+ }
141
+ const u = (l) => {
142
+ const o = t.slice(e[l], n[l]);
143
+ return o.endsWith("\r") ? o.slice(0, -1) : o;
144
+ }, s = new Array(e.length).fill(!1);
145
+ for (let l = 0; l < e.length; ) {
146
+ const o = y.exec(u(l));
147
+ if (!o) {
148
+ l++;
149
+ continue;
150
+ }
151
+ const c = o[1], f = c[0];
152
+ if (f === "`" && o[2].includes("`")) {
153
+ l++;
154
+ continue;
155
+ }
156
+ let r = -1;
157
+ for (let h = l + 1; h < e.length; h++) {
158
+ const a = S.exec(u(h));
159
+ if (a && a[1][0] === f && a[1].length >= c.length) {
160
+ r = h;
161
+ break;
162
+ }
163
+ }
164
+ if (r === -1) {
165
+ l++;
166
+ continue;
167
+ }
168
+ i.fill(E, e[l], n[r]);
169
+ for (let h = l; h <= r; h++)
170
+ s[h] = !0;
171
+ l = r + 1;
172
+ }
173
+ for (let l = 0; l < e.length; l++) {
174
+ if (s[l])
175
+ continue;
176
+ const o = e[l], c = n[l];
177
+ let f = o;
178
+ for (; f < c; ) {
179
+ if (t[f] !== "`") {
180
+ f++;
181
+ continue;
182
+ }
183
+ let r = 0;
184
+ for (; f + r < c && t[f + r] === "`"; )
185
+ r++;
186
+ if (r >= 3 && t.slice(o, f).trim() === "") {
187
+ f += r;
188
+ continue;
189
+ }
190
+ let h = f + r, a = -1;
191
+ for (; h < c; ) {
192
+ if (t[h] !== "`") {
193
+ h++;
194
+ continue;
195
+ }
196
+ let p = 0;
197
+ for (; h + p < c && t[h + p] === "`"; )
198
+ p++;
199
+ if (p === r) {
200
+ a = h;
201
+ break;
202
+ }
203
+ h += p;
204
+ }
205
+ if (a === -1) {
206
+ f += r;
207
+ continue;
208
+ }
209
+ i.fill(w, f, a + r), f = a + r;
210
+ }
211
+ }
212
+ return i;
213
+ }
214
+ function k(t, i) {
215
+ if (t[i] !== "<")
216
+ return null;
217
+ const e = t[i + 1];
218
+ if (e === void 0 || e < "A" || e > "Z")
219
+ return null;
220
+ let n = i + 2;
221
+ for (; n < t.length && /[a-zA-Z]/.test(t[n]); )
222
+ n++;
223
+ const u = t.slice(i + 1, n), s = t[n];
224
+ if (s === void 0 || s !== ">" && s !== "/" && !/\s/.test(s))
225
+ return null;
226
+ for (; n < t.length && /\s/.test(t[n]); )
227
+ n++;
228
+ const l = n, o = (f) => {
229
+ let r = f + 1;
230
+ for (; r < t.length && (t[r] === " " || t[r] === " " || t[r] === "\r"); )
231
+ r++;
232
+ return r >= t.length || t[r] === `
233
+ `;
234
+ };
235
+ let c = null;
236
+ for (; n < t.length; ) {
237
+ const f = t[n];
238
+ if (c) {
239
+ if (f === `
240
+ ` && o(n))
241
+ return null;
242
+ f === c && (c = null), n++;
243
+ continue;
244
+ }
245
+ if (f === '"' || f === "'") {
246
+ c = f, n++;
247
+ continue;
248
+ }
249
+ if (f === "{") {
250
+ const r = g(t, n);
251
+ if (!r)
252
+ return null;
253
+ n = r.endIndex;
254
+ continue;
255
+ }
256
+ if (f === "/" && t[n + 1] === ">")
257
+ return { name: u, propsSource: t.slice(l, n), tagEnd: n + 2, selfClosing: !0 };
258
+ if (f === ">")
259
+ return { name: u, propsSource: t.slice(l, n), tagEnd: n + 1, selfClosing: !1 };
260
+ if (f === "<")
261
+ return null;
262
+ if (f === `
263
+ `) {
264
+ if (o(n)) {
265
+ let r = n - 1;
266
+ for (; r >= i && /\s/.test(t[r]); )
267
+ r--;
268
+ if (t[r] === "=")
269
+ return null;
270
+ }
271
+ n++;
272
+ continue;
273
+ }
274
+ n++;
275
+ }
276
+ return null;
277
+ }
278
+ function C(t, i, e, n, u) {
279
+ const s = `</${i}`;
280
+ let l = null;
281
+ const o = u?.has(i) ?? !1, c = (r) => {
282
+ const h = `<${i}`;
283
+ let a = t.indexOf(h, e);
284
+ for (; a !== -1 && a < r; ) {
285
+ const p = t[a + h.length];
286
+ if (p === void 0 || !/[a-zA-Z]/.test(p))
287
+ return !0;
288
+ a = t.indexOf(h, a + 1);
289
+ }
290
+ return !1;
291
+ };
292
+ let f = e;
293
+ for (; f < t.length; ) {
294
+ const r = t.indexOf(s, f);
295
+ if (r === -1)
296
+ break;
297
+ let h = r + s.length;
298
+ for (; h < t.length && /\s/.test(t[h]); )
299
+ h++;
300
+ if (t[h] === ">") {
301
+ const a = { start: r, end: h + 1 };
302
+ if (n[r] === m && !c(r))
303
+ return a;
304
+ if (!l && (l = a, o))
305
+ return l;
306
+ }
307
+ f = r + s.length;
308
+ }
309
+ return l && u?.add(i), l;
310
+ }
311
+ function N(t) {
312
+ if (!t)
313
+ return [];
314
+ if (!d.test(t))
315
+ return [{ type: "html", content: t, start: 0, end: t.length }];
316
+ const i = $(t), e = [], n = /* @__PURE__ */ new Set();
317
+ let u = 0, s = 0, l = !1;
318
+ for (; s < t.length; ) {
319
+ const o = t.indexOf("<", s);
320
+ if (o === -1)
321
+ break;
322
+ if (i[o] !== m) {
323
+ s = o + 1;
324
+ continue;
325
+ }
326
+ const c = k(t, o);
327
+ if (!c) {
328
+ s = o + 1;
329
+ continue;
330
+ }
331
+ if (i[c.tagEnd - 1] === E) {
332
+ s = o + 1;
333
+ continue;
334
+ }
335
+ let f, r;
336
+ if (c.selfClosing)
337
+ f = c.tagEnd;
338
+ else {
339
+ const h = C(t, c.name, c.tagEnd, i, n);
340
+ if (!h) {
341
+ s = c.tagEnd;
342
+ continue;
343
+ }
344
+ r = t.slice(c.tagEnd, h.start).trim(), f = h.end;
345
+ }
346
+ if (o > u) {
347
+ const h = t.slice(u, o);
348
+ h.trim() && e.push({ type: "html", content: h, start: u, end: o });
349
+ }
116
350
  e.push({
117
351
  type: "component",
118
- name: r,
119
- props: h(l),
120
- children: c?.trim()
121
- }), t = s.index + s[0].length;
352
+ name: c.name,
353
+ propsSource: c.propsSource,
354
+ props: x(c.propsSource),
355
+ children: r,
356
+ start: o,
357
+ end: f
358
+ }), l = !0, u = f, s = f;
122
359
  }
123
- if (t < n.length) {
124
- const r = n.slice(t);
125
- r.trim() && e.push({ type: "html", content: r });
360
+ if (u < t.length) {
361
+ const o = t.slice(u);
362
+ o.trim() && e.push({ type: "html", content: o, start: u, end: t.length });
126
363
  }
127
- return e.length === 0 && n.trim() ? [{ type: "html", content: n }] : e;
364
+ return l ? e : t.trim() ? [{ type: "html", content: t, start: 0, end: t.length }] : [];
365
+ }
366
+ function I(t) {
367
+ if (!d.test(t))
368
+ return [{ type: "html", content: t }];
369
+ const i = N(t).map((e) => e.type === "html" ? { type: "html", content: e.content } : { type: "component", name: e.name, props: e.props, children: e.children });
370
+ return i.length === 0 && t.trim() ? [{ type: "html", content: t }] : i;
128
371
  }
129
372
  export {
130
- f as HAS_MDX_RE,
131
- u as MDX_COMPONENT_PATTERN,
132
- p as extractBraceExpression,
133
- g as extractFrontmatter,
134
- x as extractMdxComponents,
135
- h as parseJsxProps,
136
- m as serializeComponent,
137
- a as serializeProps,
138
- d as stripFrontmatter
373
+ E as CODE_FENCE,
374
+ w as CODE_INLINE,
375
+ m as CODE_NONE,
376
+ d as HAS_MDX_RE,
377
+ A as MDX_COMPONENT_PATTERN,
378
+ M as computeBodyOffset,
379
+ $ as computeCodeMask,
380
+ g as extractBraceExpression,
381
+ Z as extractFrontmatter,
382
+ I as extractMdxComponents,
383
+ z as lineAtOffset,
384
+ x as parseJsxProps,
385
+ N as scanMdxNodes,
386
+ b as serializeComponent,
387
+ O as serializeProps,
388
+ _ as stripFrontmatter
139
389
  };
@@ -2,9 +2,9 @@
2
2
  * React MDX renderer (SDK version) — Fix 3.
3
3
  *
4
4
  * Mirrors the Vue `KbMdxContent.vue` path: parses content (frontmatter strip
5
- * + `HAS_MDX_RE` fast-path + `MDX_COMPONENT_PATTERN` walk), runs prepareProps
6
- * on each item.props using getComponentMetadata, then renders via a consumer-
7
- * supplied component registry passed via prop (or via context).
5
+ * + `HAS_MDX_RE` fast-path + `extractMdxComponents`), runs prepareProps on each
6
+ * item.props using getComponentMetadata, then renders via a consumer-supplied
7
+ * component registry passed via prop (or via context).
8
8
  *
9
9
  * Framework-neutral by design: the SDK does NOT depend on
10
10
  * `@blogmcp/mdx-render-react`. Consumers that want the built-in render
@@ -1,102 +1,94 @@
1
- import { createElement as i, Fragment as _ } from "react";
2
- import { Marked as b } from "marked";
3
- import { stripFrontmatter as M, HAS_MDX_RE as k, parseJsxProps as v, MDX_COMPONENT_PATTERN as w } from "../packages/mdx-schema/dist/composables/useMdxParsing.js";
4
- import { sanitizeHtml as p } from "../packages/sanitize/dist/html.js";
1
+ import { createElement as s, Fragment as f } from "react";
2
+ import { Marked as h } from "marked";
3
+ import { stripFrontmatter as y, HAS_MDX_RE as g, extractMdxComponents as b } from "../packages/mdx-schema/dist/composables/useMdxParsing.js";
4
+ import { sanitizeHtml as d } from "../packages/sanitize/dist/html.js";
5
5
  import "../_virtual/index.js";
6
- import { defaultImageHtml as $ } from "../core/markdown.js";
7
- import { prepareProps as N } from "../packages/mdx-schema/dist/prepareProps.js";
8
- import { getComponentMetadata as H } from "../packages/mdx-schema/dist/metadata/index.js";
9
- function h(l) {
10
- return new b({
6
+ import { defaultImageHtml as k } from "../core/markdown.js";
7
+ import { prepareProps as v } from "../packages/mdx-schema/dist/prepareProps.js";
8
+ import { getComponentMetadata as M } from "../packages/mdx-schema/dist/metadata/index.js";
9
+ function c(m) {
10
+ return new h({
11
11
  renderer: {
12
- image({ href: e, title: t, text: s }) {
13
- return e ? l(e, s, t) : "";
12
+ image({ href: t, title: r, text: n }) {
13
+ return t ? m(t, n, r) : "";
14
14
  },
15
- link({ href: e, title: t, text: s }) {
16
- const r = t ? ` title="${t}"` : "";
17
- return e && /^https?:\/\//.test(e) ? `<a href="${e}"${r} target="_blank" rel="noopener noreferrer">${s}</a>` : `<a href="${e}"${r}>${s}</a>`;
15
+ link({ href: t, title: r, text: n }) {
16
+ const e = r ? ` title="${r}"` : "";
17
+ return t && /^https?:\/\//.test(t) ? `<a href="${t}"${e} target="_blank" rel="noopener noreferrer">${n}</a>` : `<a href="${t}"${e}>${n}</a>`;
18
18
  }
19
19
  },
20
20
  hooks: {
21
- postprocess(e) {
22
- return e.replace(/<table>/g, '<div class="overflow-x-auto -mx-4 px-4"><table>').replace(/<\/table>/g, "</table></div>").replace(/<th>/g, '<th scope="col">');
21
+ postprocess(t) {
22
+ return t.replace(/<table>/g, '<div class="overflow-x-auto -mx-4 px-4"><table>').replace(/<\/table>/g, "</table></div>").replace(/<th>/g, '<th scope="col">');
23
23
  }
24
24
  }
25
25
  });
26
26
  }
27
- function f(l, e) {
28
- if (!l) return { mode: "html", html: "", items: [] };
29
- const t = M(l);
30
- if (!k.test(t))
31
- return { mode: "html", html: p(e.parse(t)), items: [] };
32
- const s = new RegExp(w.source, "g"), r = [];
33
- let o = 0, n;
34
- for (; (n = s.exec(t)) !== null; ) {
35
- if (n.index > o) {
36
- const u = t.slice(o, n.index);
37
- u.trim() && r.push({ type: "html", content: p(e.parse(u)) });
38
- }
39
- const m = n[1] || n[4] || "", a = n[1] ? n[2] || "" : n[5] || "", y = n[3], c = v(a), d = H(m), x = d ? N(c, d) : c;
40
- r.push({
27
+ function i(m, t) {
28
+ if (!m) return { mode: "html", html: "", items: [] };
29
+ const r = y(m);
30
+ if (!g.test(r))
31
+ return { mode: "html", html: d(t.parse(r)), items: [] };
32
+ const n = b(r).map((e) => {
33
+ if (e.type === "html")
34
+ return { type: "html", content: d(t.parse(e.content ?? "")) };
35
+ const o = M(e.name ?? ""), l = e.props ?? {};
36
+ return {
41
37
  type: "component",
42
- name: m,
43
- props: x,
44
- children: y?.trim()
45
- }), o = n.index + n[0].length;
46
- }
47
- if (o < t.length) {
48
- const m = t.slice(o);
49
- m.trim() && r.push({ type: "html", content: p(e.parse(m)) });
50
- }
51
- return r.length === 0 && t.trim() ? { mode: "html", html: p(e.parse(t)), items: [] } : { mode: "mdx", items: r, html: "" };
38
+ name: e.name,
39
+ props: o ? v(l, o) : l,
40
+ children: e.children
41
+ };
42
+ });
43
+ return !n.some((e) => e.type === "component") && r.trim() ? { mode: "html", html: d(t.parse(r)), items: [] } : { mode: "mdx", items: n, html: "" };
52
44
  }
53
- function g(l, e, t) {
54
- const s = h(t);
55
- return l.map((r, o) => {
56
- if (r.type === "html")
57
- return i("div", {
45
+ function u(m, t, r) {
46
+ const n = c(r);
47
+ return m.map((e, o) => {
48
+ if (e.type === "html")
49
+ return s("div", {
58
50
  key: o,
59
- dangerouslySetInnerHTML: { __html: r.content }
51
+ dangerouslySetInnerHTML: { __html: e.content }
60
52
  });
61
- const n = e[r.name];
62
- if (!n)
63
- return i(
53
+ const l = t[e.name];
54
+ if (!l)
55
+ return s(
64
56
  "div",
65
57
  {
66
58
  key: o,
67
59
  className: "bg-yellow-50 border border-yellow-200 rounded-lg p-4 my-4 text-yellow-800"
68
60
  },
69
- `Unknown component: ${r.name}`
61
+ `Unknown component: ${e.name}`
70
62
  );
71
- let m;
72
- if (r.children) {
73
- const a = f(r.children, s);
74
- a.mode === "html" ? m = i("div", {
75
- dangerouslySetInnerHTML: { __html: a.html }
76
- }) : m = g(a.items, e, t);
63
+ let a;
64
+ if (e.children) {
65
+ const p = i(e.children, n);
66
+ p.mode === "html" ? a = s("div", {
67
+ dangerouslySetInnerHTML: { __html: p.html }
68
+ }) : a = u(p.items, t, r);
77
69
  }
78
- return i(n, { key: o, ...r.props }, m);
70
+ return s(l, { key: o, ...e.props }, a);
79
71
  });
80
72
  }
81
- function R({
82
- content: l,
83
- components: e = {},
84
- imageRenderer: t
73
+ function S({
74
+ content: m,
75
+ components: t = {},
76
+ imageRenderer: r
85
77
  }) {
86
- const s = t ?? $, r = h(s), o = f(l, r);
78
+ const n = r ?? k, e = c(n), o = i(m, e);
87
79
  if (o.mode === "html")
88
- return i("div", {
80
+ return s("div", {
89
81
  className: "mdx-content",
90
82
  dangerouslySetInnerHTML: { __html: o.html }
91
83
  });
92
- const n = g(o.items, e, s);
93
- return i(
84
+ const l = u(o.items, t, n);
85
+ return s(
94
86
  "div",
95
87
  { className: "mdx-content" },
96
- n.map((m, a) => i(_, { key: a }, m))
88
+ l.map((a, p) => s(f, { key: p }, a))
97
89
  );
98
90
  }
99
91
  export {
100
- R as KbMdxContent,
101
- R as default
92
+ S as KbMdxContent,
93
+ S as default
102
94
  };
package/dist/sdk.css CHANGED
@@ -1 +1 @@
1
- .mdx-content[data-v-920ab56a] .broken-image{display:inline-block;min-height:4rem;min-width:8rem;background:#f3f4f6;border:1px dashed #d1d5db;border-radius:.5rem}
1
+ .mdx-content[data-v-96f4a7ef] .broken-image{display:inline-block;min-height:4rem;min-width:8rem;background:#f3f4f6;border:1px dashed #d1d5db;border-radius:.5rem}
@@ -1,7 +1,7 @@
1
1
  import o from "./KbMdxContent.vue2.js";
2
2
  /* empty css */
3
3
  import t from "../../_virtual/_plugin-vue_export-helper.js";
4
- const p = /* @__PURE__ */ t(o, [["__scopeId", "data-v-920ab56a"]]);
4
+ const e = /* @__PURE__ */ t(o, [["__scopeId", "data-v-96f4a7ef"]]);
5
5
  export {
6
- p as default
6
+ e as default
7
7
  };
@@ -1,82 +1,79 @@
1
- import { defineComponent as L, withAsyncContext as x, inject as b, computed as E, createElementBlock as g, openBlock as l, Fragment as B, renderList as I, createBlock as O, resolveDynamicComponent as X, h as a } from "vue";
2
- import { KB_IMAGE_RENDERER_KEY as F } from "../plugin.js";
3
- import { defaultImageHtml as K, createMarkedInstance as Z, parseMarkdownSafe as z } from "../../core/markdown.js";
4
- import { prepareProps as J } from "../../packages/mdx-schema/dist/prepareProps.js";
5
- import { getComponentMetadata as W } from "../../packages/mdx-schema/dist/metadata/index.js";
6
- import { sanitizeHtml as j } from "../../packages/sanitize/dist/html.js";
1
+ import { defineComponent as R, withAsyncContext as k, inject as E, computed as C, createElementBlock as y, openBlock as s, Fragment as A, renderList as L, createBlock as b, resolveDynamicComponent as B, h as c } from "vue";
2
+ import { KB_IMAGE_RENDERER_KEY as D } from "../plugin.js";
3
+ import { defaultImageHtml as S, createMarkedInstance as T, parseMarkdownSafe as F } from "../../core/markdown.js";
4
+ import { prepareProps as I } from "../../packages/mdx-schema/dist/prepareProps.js";
5
+ import { getComponentMetadata as K } from "../../packages/mdx-schema/dist/metadata/index.js";
6
+ import { sanitizeHtml as P } from "../../packages/sanitize/dist/html.js";
7
7
  import "../../_virtual/index.js";
8
- const G = { class: "mdx-content" }, U = ["innerHTML"], ne = /* @__PURE__ */ L({
8
+ const W = { class: "mdx-content" }, X = ["innerHTML"], $ = /* @__PURE__ */ R({
9
9
  __name: "KbMdxContent",
10
10
  props: {
11
11
  content: {}
12
12
  },
13
- async setup(R) {
14
- let s, p, d, u, f, h, c, _;
13
+ async setup(g) {
14
+ let r, m, a, l, i, p, d;
15
15
  try {
16
- const e = ([s, p] = x(() => import("../../packages/mdx-schema/dist/composables/useMdxParsing.js")), s = await s, p(), s);
17
- d = e.parseJsxProps, u = e.stripFrontmatter, f = e.HAS_MDX_RE, h = e.MDX_COMPONENT_PATTERN;
18
- const n = ([s, p] = x(() => import("../../packages/mdx-render-vue/dist/registry.js")), s = await s, p(), s);
19
- c = n.getWrappedRenderComponent, _ = (t) => t in n.componentRegistry;
16
+ const e = ([r, m] = k(() => import("../../packages/mdx-schema/dist/composables/useMdxParsing.js")), r = await r, m(), r);
17
+ a = e.stripFrontmatter, l = e.HAS_MDX_RE, i = e.extractMdxComponents;
18
+ const n = ([r, m] = k(() => import("../../packages/mdx-render-vue/dist/registry.js")), r = await r, m(), r);
19
+ p = n.getWrappedRenderComponent, d = (t) => t in n.componentRegistry;
20
20
  } catch {
21
- d = () => ({}), u = (e) => e.replace(/^---[\s\S]*?---\n?/, ""), f = /<[A-Z]/, h = /<([A-Z]\w+)([^>]*)>([\s\S]*?)<\/\1>|<([A-Z]\w+)([^>]*)\/>/, c = null, _ = () => !1;
21
+ a = (e) => e.replace(/^---[\s\S]*?---\n?/, ""), l = /<[A-Z]/, i = (e) => [{ type: "html", content: e }], p = null, d = () => !1;
22
22
  }
23
- const M = R, v = b(F, K);
24
- function H(e) {
25
- if (c && _(e))
26
- return c(e, "default");
23
+ const h = g, M = E(D, S);
24
+ function v(e) {
25
+ if (p && d(e))
26
+ return p(e, "default");
27
27
  }
28
- const T = Z({
29
- imageRenderer: v
28
+ const H = T({
29
+ imageRenderer: M
30
30
  // sanitize: undefined — parseMarkdownSafe applies it below
31
31
  });
32
- function i(e) {
33
- return z(e, T, j);
32
+ function u(e) {
33
+ return F(e, H, P);
34
34
  }
35
- const y = E(() => {
36
- if (!M.content) return { mode: "html", html: "", items: [] };
37
- const e = u(M.content);
38
- if (!f.test(e))
39
- return { mode: "html", html: i(e), items: [] };
40
- const n = new RegExp(h.source, "g"), t = [];
41
- let o = 0, r;
42
- for (; (r = n.exec(e)) !== null; ) {
43
- if (r.index > o) {
44
- const w = e.slice(o, r.index);
45
- w.trim() && t.push({ type: "html", content: i(w) });
46
- }
47
- const m = r[1] || r[4] || "", N = r[1] ? r[2] || "" : r[5] || "", D = r[3], k = d(N), C = W(m), S = C ? J(k, C) : k;
48
- t.push({ type: "component", name: m, props: S, children: D?.trim() }), o = r.index + r[0].length;
49
- }
50
- if (o < e.length) {
51
- const m = e.slice(o);
52
- m.trim() && t.push({ type: "html", content: i(m) });
53
- }
54
- return t.length === 0 && e.trim() ? { mode: "html", html: i(e), items: [] } : { mode: "mdx", html: "", items: t };
35
+ const f = C(() => {
36
+ if (!h.content) return { mode: "html", html: "", items: [] };
37
+ const e = a(h.content);
38
+ if (!l.test(e))
39
+ return { mode: "html", html: u(e), items: [] };
40
+ const n = i(e).map((t) => {
41
+ if (t.type === "html")
42
+ return { type: "html", content: u(t.content ?? "") };
43
+ const o = K(t.name ?? ""), _ = t.props ?? {};
44
+ return {
45
+ type: "component",
46
+ name: t.name,
47
+ props: o ? I(_, o) : _,
48
+ children: t.children
49
+ };
50
+ });
51
+ return !n.some((t) => t.type === "component") && e.trim() ? { mode: "html", html: u(e), items: [] } : { mode: "mdx", html: "", items: n };
55
52
  });
56
- function A(e) {
53
+ function w(e) {
57
54
  return e.map((n, t) => {
58
55
  if (n.type === "html")
59
- return a("div", { key: t, innerHTML: n.content });
56
+ return c("div", { key: t, innerHTML: n.content });
60
57
  if (n.type === "component") {
61
- const o = H(n.name);
62
- return o ? a(o, { key: t, ...n.props }, () => n.children) : a("div", {
58
+ const o = v(n.name);
59
+ return o ? c(o, { key: t, ...n.props }, () => n.children) : c("div", {
63
60
  key: t,
64
61
  class: "bg-yellow-50 border border-yellow-200 rounded-lg p-4 my-4 text-yellow-800",
65
62
  innerHTML: `Unknown component: ${n.name}`
66
63
  });
67
64
  }
68
- return a("span", { key: t });
65
+ return c("span", { key: t });
69
66
  });
70
67
  }
71
- const P = E(() => A(y.value.items));
72
- return (e, n) => (l(), g("div", G, [
73
- y.value.mode === "mdx" ? (l(!0), g(B, { key: 0 }, I(P.value, (t, o) => (l(), O(X(t), { key: o }))), 128)) : (l(), g("div", {
68
+ const x = C(() => w(f.value.items));
69
+ return (e, n) => (s(), y("div", W, [
70
+ f.value.mode === "mdx" ? (s(!0), y(A, { key: 0 }, L(x.value, (t, o) => (s(), b(B(t), { key: o }))), 128)) : (s(), y("div", {
74
71
  key: 1,
75
- innerHTML: y.value.html
76
- }, null, 8, U))
72
+ innerHTML: f.value.html
73
+ }, null, 8, X))
77
74
  ]));
78
75
  }
79
76
  });
80
77
  export {
81
- ne as default
78
+ $ as default
82
79
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blogmcp/sdk",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "Headless SDK for Knowledge Base blog — core client, Vue composables, Nuxt adapter",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -61,8 +61,8 @@
61
61
  }
62
62
  },
63
63
  "dependencies": {
64
- "@blogmcp/mdx-schema": "^0.2.2",
65
- "@blogmcp/sanitize": "^0.2.2",
64
+ "@blogmcp/mdx-schema": "^0.3.0",
65
+ "@blogmcp/sanitize": "^0.3.0",
66
66
  "marked": "^15.0.7"
67
67
  },
68
68
  "optionalDependencies": {
@@ -2,9 +2,9 @@
2
2
  * React MDX renderer (SDK version) — Fix 3.
3
3
  *
4
4
  * Mirrors the Vue `KbMdxContent.vue` path: parses content (frontmatter strip
5
- * + `HAS_MDX_RE` fast-path + `MDX_COMPONENT_PATTERN` walk), runs prepareProps
6
- * on each item.props using getComponentMetadata, then renders via a consumer-
7
- * supplied component registry passed via prop (or via context).
5
+ * + `HAS_MDX_RE` fast-path + `extractMdxComponents`), runs prepareProps on each
6
+ * item.props using getComponentMetadata, then renders via a consumer-supplied
7
+ * component registry passed via prop (or via context).
8
8
  *
9
9
  * Framework-neutral by design: the SDK does NOT depend on
10
10
  * `@blogmcp/mdx-render-react`. Consumers that want the built-in render
@@ -25,8 +25,7 @@ import {
25
25
  import { Marked } from 'marked'
26
26
  import {
27
27
  HAS_MDX_RE,
28
- MDX_COMPONENT_PATTERN,
29
- parseJsxProps,
28
+ extractMdxComponents,
30
29
  stripFrontmatter,
31
30
  } from '@blogmcp/mdx-schema/composables/parsing'
32
31
  import { sanitizeHtml } from '@blogmcp/sanitize'
@@ -96,44 +95,31 @@ function parseContent(content: string, marked: Marked):
96
95
  return { mode: 'html', html: sanitizeHtml(marked.parse(source) as string), items: [] }
97
96
  }
98
97
 
99
- const componentRe = new RegExp(MDX_COMPONENT_PATTERN.source, 'g')
100
- const items: ParsedItem[] = []
101
- let lastIndex = 0
102
- let match: RegExpExecArray | null
103
-
104
- while ((match = componentRe.exec(source)) !== null) {
105
- if (match.index > lastIndex) {
106
- const md = source.slice(lastIndex, match.index)
107
- if (md.trim()) {
108
- items.push({ type: 'html', content: sanitizeHtml(marked.parse(md) as string) })
109
- }
98
+ // `extractMdxComponents`, NOT a local `MDX_COMPONENT_PATTERN` walk. The regex cannot express
99
+ // either half of correct extraction, and re-walking it here meant this renderer carried both
100
+ // scanner bugs independently of the validator: a prose `<Gallery>` mention ran to the next '/>'
101
+ // anywhere in the document (measured 142 lines / 8916 chars on one shipped page, 81.7% of its body
102
+ // never reaching the reader), and a component shown inside a ``` fence rendered as a LIVE one.
103
+ // See the @deprecated block on MDX_COMPONENT_PATTERN for the full measurements.
104
+ const items: ParsedItem[] = extractMdxComponents(source).map((item) => {
105
+ if (item.type === 'html') {
106
+ return { type: 'html', content: sanitizeHtml(marked.parse(item.content ?? '') as string) }
110
107
  }
111
- const name = match[1] || match[4] || ''
112
- const propsStr = match[1] ? match[2] || '' : match[5] || ''
113
- const children = match[3]
114
- const rawProps = parseJsxProps(propsStr)
115
- // Normalize against the schema's deprecation entries (parallel of the
116
- // Vue path). Fix 2/3: the SDK guarantees normalized props REGARDLESS of
117
- // which renderer the consumer wires.
118
- const meta = getComponentMetadata(name)
119
- const normalizedProps = meta ? prepareProps(rawProps, meta) : rawProps
120
- items.push({
108
+ // Normalize against the schema's deprecation entries (parallel of the Vue path). Fix 2/3: the
109
+ // SDK guarantees normalized props REGARDLESS of which renderer the consumer wires.
110
+ const meta = getComponentMetadata(item.name ?? '')
111
+ const rawProps = item.props ?? {}
112
+ return {
121
113
  type: 'component',
122
- name,
123
- props: normalizedProps,
124
- children: children?.trim(),
125
- })
126
- lastIndex = match.index + match[0].length
127
- }
128
-
129
- if (lastIndex < source.length) {
130
- const remaining = source.slice(lastIndex)
131
- if (remaining.trim()) {
132
- items.push({ type: 'html', content: sanitizeHtml(marked.parse(remaining) as string) })
114
+ name: item.name,
115
+ props: meta ? prepareProps(rawProps, meta) : rawProps,
116
+ children: item.children,
133
117
  }
134
- }
118
+ })
135
119
 
136
- if (items.length === 0 && source.trim()) {
120
+ // No component survived the scan (e.g. every occurrence is inside a code fence) → take the
121
+ // pure-markdown path, so a document that only DOCUMENTS components renders as the code it is.
122
+ if (!items.some((i) => i.type === 'component') && source.trim()) {
137
123
  return { mode: 'html', html: sanitizeHtml(marked.parse(source) as string), items: [] }
138
124
  }
139
125
 
@@ -32,10 +32,9 @@ import { sanitizeHtml } from '@blogmcp/sanitize'
32
32
 
33
33
  // Import from @blogmcp/mdx-render-vue (peer dependency in consumer's app)
34
34
  // These are re-exported parsing utilities + the prepareProps-aware getter.
35
- let parseJsxProps: (str: string) => Record<string, unknown>
36
35
  let stripFrontmatter: (content: string) => string
37
36
  let HAS_MDX_RE: RegExp
38
- let MDX_COMPONENT_PATTERN: RegExp
37
+ let extractMdxComponents: (content: string) => ParsedContent[]
39
38
  let getWrappedRenderComponent: ((name: string, variant?: string) => Component | undefined) | null
40
39
  let registryHasComponent: (name: string) => boolean
41
40
 
@@ -47,20 +46,30 @@ let registryHasComponent: (name: string) => boolean
47
46
  // packages/mdx-render-vue/src/registry.ts for the wrapper implementation.
48
47
  try {
49
48
  const parsing = await import('@blogmcp/mdx-schema/composables/parsing')
50
- parseJsxProps = parsing.parseJsxProps
51
49
  stripFrontmatter = parsing.stripFrontmatter
52
50
  HAS_MDX_RE = parsing.HAS_MDX_RE
53
- MDX_COMPONENT_PATTERN = parsing.MDX_COMPONENT_PATTERN
51
+ extractMdxComponents = parsing.extractMdxComponents
54
52
 
55
53
  const registry = await import('@blogmcp/mdx-render-vue/registry')
56
54
  getWrappedRenderComponent = registry.getWrappedRenderComponent
57
55
  registryHasComponent = (name: string) => name in registry.componentRegistry
58
56
  } catch {
59
- // Fallback: no MDX component support — render as pure markdown
60
- parseJsxProps = () => ({})
57
+ // Fallback: no MDX component support — render as pure markdown.
58
+ //
59
+ // ⚠ This branch used to carry its OWN component regex
60
+ // /<([A-Z]\w+)([^>]*)>([\s\S]*?)<\/\1>|<([A-Z]\w+)([^>]*)\/>/
61
+ // which was both divergent from the real scanner (`\w+` names, `[^>]*` on BOTH branches,
62
+ // non-global) and actively DESTRUCTIVE here: it split the document into component items while
63
+ // `registryHasComponent` is hardcoded `false` in this branch, so every component it found rendered
64
+ // as an "Unknown component" box and the surrounding text was fragmented around content that could
65
+ // never appear. It could also never inherit a scanner fix, by construction.
66
+ //
67
+ // Returning one html node instead routes this branch through the pure-markdown path below, so the
68
+ // prose survives intact and the sanitizer drops the unknown tags — the best available degradation
69
+ // when the schema package cannot be loaded at all.
61
70
  stripFrontmatter = (c: string) => c.replace(/^---[\s\S]*?---\n?/, '')
62
71
  HAS_MDX_RE = /<[A-Z]/
63
- MDX_COMPONENT_PATTERN = /<([A-Z]\w+)([^>]*)>([\s\S]*?)<\/\1>|<([A-Z]\w+)([^>]*)\/>/
72
+ extractMdxComponents = (c: string) => [{ type: 'html', content: c }]
64
73
  getWrappedRenderComponent = null
65
74
  registryHasComponent = () => false
66
75
  }
@@ -119,42 +128,36 @@ const parsed = computed<{ mode: 'html' | 'mdx'; html: string; items: ParsedConte
119
128
  return { mode: 'html', html: renderHtml(content), items: [] }
120
129
  }
121
130
 
122
- // MDX path
123
- const componentRe = new RegExp(MDX_COMPONENT_PATTERN.source, 'g')
124
- const items: ParsedContent[] = []
125
- let lastIndex = 0
126
- let match
127
-
128
- while ((match = componentRe.exec(content)) !== null) {
129
- if (match.index > lastIndex) {
130
- const md = content.slice(lastIndex, match.index)
131
- if (md.trim()) {
132
- items.push({ type: 'html', content: renderHtml(md) })
133
- }
131
+ // MDX path — `extractMdxComponents`, NOT a local MDX_COMPONENT_PATTERN walk. The regex cannot
132
+ // express either half of correct extraction, so re-walking it here meant this renderer carried both
133
+ // scanner bugs independently: a prose `<Gallery>` mention ran to the next '/>' anywhere in the
134
+ // document (81.7% of one shipped page never reached the reader), and a component shown inside a
135
+ // ``` fence rendered as a LIVE one. See the @deprecated block on MDX_COMPONENT_PATTERN.
136
+ //
137
+ // ⚠ `item.content` on an html node is RAW markdown; this renderer stores RENDERED HTML in that
138
+ // field (it goes straight into `innerHTML` in renderContent), so every html node must pass through
139
+ // renderHtml — which is also where sanitization happens.
140
+ const items: ParsedContent[] = extractMdxComponents(content).map((item) => {
141
+ if (item.type === 'html') {
142
+ return { type: 'html', content: renderHtml(item.content ?? '') }
134
143
  }
135
- const name = match[1] || match[4] || ''
136
- const propsStr = match[1] ? (match[2] || '') : (match[5] || '')
137
- const children = match[3]
138
- const rawProps = parseJsxProps(propsStr)
139
- // Normalize against the schema's deprecation entries BEFORE handing the
140
- // props to the renderer. The bundled Vue registry's `getWrappedRenderComponent`
141
- // also runs prepareProps, so this is a no-op there (idempotent), but
142
- // custom-registered components OR consumers that skipped mdx-render-vue
143
- // entirely still get a normalized props object. See Fix 2.
144
- const meta = getComponentMetadata(name)
145
- const normalizedProps = meta ? prepareProps(rawProps, meta) : rawProps
146
- items.push({ type: 'component', name, props: normalizedProps, children: children?.trim() })
147
- lastIndex = match.index + match[0].length
148
- }
149
-
150
- if (lastIndex < content.length) {
151
- const remaining = content.slice(lastIndex)
152
- if (remaining.trim()) {
153
- items.push({ type: 'html', content: renderHtml(remaining) })
144
+ // Normalize against the schema's deprecation entries BEFORE handing the props to the renderer.
145
+ // The bundled Vue registry's `getWrappedRenderComponent` also runs prepareProps, so this is a
146
+ // no-op there (idempotent), but custom-registered components OR consumers that skipped
147
+ // mdx-render-vue entirely still get a normalized props object. See Fix 2.
148
+ const meta = getComponentMetadata(item.name ?? '')
149
+ const rawProps = item.props ?? {}
150
+ return {
151
+ type: 'component',
152
+ name: item.name,
153
+ props: meta ? prepareProps(rawProps, meta) : rawProps,
154
+ children: item.children,
154
155
  }
155
- }
156
+ })
156
157
 
157
- if (items.length === 0 && content.trim()) {
158
+ // No component survived the scan (every occurrence inside code, or the fallback branch above) →
159
+ // pure markdown, so a page that only DOCUMENTS components renders as the code it is.
160
+ if (!items.some((i) => i.type === 'component') && content.trim()) {
158
161
  return { mode: 'html', html: renderHtml(content), items: [] }
159
162
  }
160
163