@emberkit/core 0.3.6 → 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;AA6hCD,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"}
@@ -285,11 +285,9 @@ async function transformMDX(code, _id) {
285
285
  let body = typeof compiled === 'object' && compiled !== null && 'value' in compiled
286
286
  ? String(compiled.value)
287
287
  : String(compiled);
288
- // Rename the @mdx-js/mdx default export so we can wrap it with the
289
- // md-doc / md-content styling containers that the docs CSS targets.
288
+ body = enhanceMDXCodeBlocks(body);
289
+ body = enhanceMDXHeadings(body);
290
290
  body = body.replace(/export default function MDXContent/, 'function _MDXContent');
291
- // Wrapper re-exports the component with the styling containers.
292
- // We reuse _jsx/_jsxs already imported by the compiled output.
293
291
  const wrapper = `
294
292
  export default function MDXComponent(props) {
295
293
  var p = props ?? {};
@@ -304,6 +302,39 @@ export default function MDXComponent(props) {
304
302
  `;
305
303
  return { code: insertAfterLeadingImports(body + wrapper, exportLines.join('\n')) };
306
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
+ });
337
+ }
307
338
  function parseFrontmatter(content) {
308
339
  const result = {};
309
340
  const lines = content.split('\n');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@emberkit/core",
3
- "version": "0.3.6",
3
+ "version": "0.3.7",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "description": "Lightweight TypeScript-first JSX framework core",