@emberkit/core 0.3.5 → 0.3.7

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 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/vite-plugin/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,MAAM,CAAC;AAClD,OAAO,KAAK,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AA8CtE,wBAAgB,kBAAkB,CAAC,WAAW,GAAE,qBAA0B,GAAG,MAAM,CA8IlF;AAugCD,YAAY,EAAE,qBAAqB,EAAE,YAAY,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/vite-plugin/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,MAAM,CAAC;AAClD,OAAO,KAAK,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AA8CtE,wBAAgB,kBAAkB,CAAC,WAAW,GAAE,qBAA0B,GAAG,MAAM,CA8IlF;AAskCD,YAAY,EAAE,qBAAqB,EAAE,YAAY,EAAE,CAAC"}
@@ -282,10 +282,58 @@ async function transformMDX(code, _id) {
282
282
  exportLines.push(`export const date = ${JSON.stringify(frontmatter.date)};`);
283
283
  }
284
284
  exportLines.push(`export const metadata = ${JSON.stringify(frontmatter)};`);
285
- const body = typeof compiled === 'object' && compiled !== null && 'value' in compiled
285
+ let body = typeof compiled === 'object' && compiled !== null && 'value' in compiled
286
286
  ? String(compiled.value)
287
287
  : String(compiled);
288
- return { code: insertAfterLeadingImports(body, exportLines.join('\n')) };
288
+ body = enhanceMDXCodeBlocks(body);
289
+ body = enhanceMDXHeadings(body);
290
+ body = body.replace(/export default function MDXContent/, 'function _MDXContent');
291
+ const wrapper = `
292
+ export default function MDXComponent(props) {
293
+ var p = props ?? {};
294
+ return _jsx('article', {
295
+ className: 'md-doc',
296
+ children: _jsx('div', {
297
+ className: 'md-content',
298
+ children: _jsx(_MDXContent, p)
299
+ })
300
+ });
301
+ }
302
+ `;
303
+ return { code: insertAfterLeadingImports(body + wrapper, exportLines.join('\n')) };
304
+ }
305
+ /** Add `id` attributes to headings with simple text children for anchor linking. */
306
+ function enhanceMDXHeadings(jsCode) {
307
+ const headingRe = /_jsx\(_components\.(h[1-6]),\s*\{\s*children:\s*("(?:[^"\\]|\\.)*")\s*\}\)/g;
308
+ return jsCode.replace(headingRe, (_match, tag, textStr) => {
309
+ const text = JSON.parse(textStr);
310
+ const id = text
311
+ .toLowerCase()
312
+ .replace(/[^\w]+/g, '-')
313
+ .replace(/^-|-$/g, '');
314
+ return `_jsx(_components.${tag}, { id: ${JSON.stringify(id)}, children: ${textStr} })`;
315
+ });
316
+ }
317
+ /**
318
+ * Post-process the compiled MDX JS output to replace plain `<pre><code>`
319
+ * blocks with syntax-highlighted code blocks that include copy buttons
320
+ * and `data-lang` attributes — matching the HTML that the `.md` transform
321
+ * produces via `renderCodeBlock`.
322
+ */
323
+ function enhanceMDXCodeBlocks(jsCode) {
324
+ const codeBlockRe = /_jsx\(_components\.pre,\s*\{\s*children:\s*_jsx\(_components\.code,\s*\{(?:\s*className:\s*"language-([^"]+)",)?\s*children:\s*("(?:[^"\\]|\\.)*")\s*\}\)\s*\}\)/g;
325
+ return jsCode.replace(codeBlockRe, (_match, lang, codeStr) => {
326
+ const rawCode = JSON.parse(codeStr);
327
+ const language = lang ?? '';
328
+ const fullHtml = renderCodeBlock(language, rawCode);
329
+ const innerHtml = fullHtml.replace(/^<pre[^>]*>/, '').replace(/<\/pre>$/, '');
330
+ const attrs = [];
331
+ if (language) {
332
+ attrs.push(`"data-lang": ${JSON.stringify(language)}`);
333
+ }
334
+ attrs.push(`dangerouslySetInnerHTML: { __html: ${JSON.stringify(innerHtml)} }`);
335
+ return `_jsx("pre", { ${attrs.join(', ')} })`;
336
+ });
289
337
  }
290
338
  function parseFrontmatter(content) {
291
339
  const result = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@emberkit/core",
3
- "version": "0.3.5",
3
+ "version": "0.3.7",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "description": "Lightweight TypeScript-first JSX framework core",