@astrojs/mdx 4.3.13 → 5.0.0-beta.1
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.js +1 -2
- package/dist/plugins.d.ts +0 -1
- package/dist/plugins.js +3 -6
- package/dist/vite-plugin-mdx-postprocess.js +18 -9
- package/dist/vite-plugin-mdx.d.ts +0 -1
- package/dist/vite-plugin-mdx.js +46 -37
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -58,8 +58,7 @@ function mdx(partialMdxOptions = {}) {
|
|
|
58
58
|
});
|
|
59
59
|
Object.assign(vitePluginMdxOptions, {
|
|
60
60
|
mdxOptions: resolvedMdxOptions,
|
|
61
|
-
srcDir: config.srcDir
|
|
62
|
-
experimentalHeadingIdCompat: config.experimental.headingIdCompat
|
|
61
|
+
srcDir: config.srcDir
|
|
63
62
|
});
|
|
64
63
|
vitePluginMdxOptions = {};
|
|
65
64
|
}
|
package/dist/plugins.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { MdxOptions } from './index.js';
|
|
2
2
|
interface MdxProcessorExtraOptions {
|
|
3
3
|
sourcemap: boolean;
|
|
4
|
-
experimentalHeadingIdCompat: boolean;
|
|
5
4
|
}
|
|
6
5
|
export declare function createMdxProcessor(mdxOptions: MdxOptions, extraOptions: MdxProcessorExtraOptions): import("unified").Processor<import("mdast").Root, import("estree").Program, import("estree").Program, import("estree").Program, string>;
|
|
7
6
|
export {};
|
package/dist/plugins.js
CHANGED
|
@@ -19,7 +19,7 @@ const isPerformanceBenchmark = Boolean(process.env.ASTRO_PERFORMANCE_BENCHMARK);
|
|
|
19
19
|
function createMdxProcessor(mdxOptions, extraOptions) {
|
|
20
20
|
return createProcessor({
|
|
21
21
|
remarkPlugins: getRemarkPlugins(mdxOptions),
|
|
22
|
-
rehypePlugins: getRehypePlugins(mdxOptions
|
|
22
|
+
rehypePlugins: getRehypePlugins(mdxOptions),
|
|
23
23
|
recmaPlugins: mdxOptions.recmaPlugins,
|
|
24
24
|
remarkRehypeOptions: mdxOptions.remarkRehype,
|
|
25
25
|
jsxImportSource: "astro",
|
|
@@ -43,7 +43,7 @@ function getRemarkPlugins(mdxOptions) {
|
|
|
43
43
|
remarkPlugins.push(...mdxOptions.remarkPlugins, remarkCollectImages);
|
|
44
44
|
return remarkPlugins;
|
|
45
45
|
}
|
|
46
|
-
function getRehypePlugins(mdxOptions
|
|
46
|
+
function getRehypePlugins(mdxOptions) {
|
|
47
47
|
let rehypePlugins = [
|
|
48
48
|
// ensure `data.meta` is preserved in `properties.metastring` for rehype syntax highlighters
|
|
49
49
|
rehypeMetaString,
|
|
@@ -62,10 +62,7 @@ function getRehypePlugins(mdxOptions, { experimentalHeadingIdCompat }) {
|
|
|
62
62
|
}
|
|
63
63
|
rehypePlugins.push(...mdxOptions.rehypePlugins, rehypeImageToComponent);
|
|
64
64
|
if (!isPerformanceBenchmark) {
|
|
65
|
-
rehypePlugins.push(
|
|
66
|
-
[rehypeHeadingIds, { experimentalHeadingIdCompat }],
|
|
67
|
-
rehypeInjectHeadingsExport
|
|
68
|
-
);
|
|
65
|
+
rehypePlugins.push([rehypeHeadingIds], rehypeInjectHeadingsExport);
|
|
69
66
|
}
|
|
70
67
|
rehypePlugins.push(
|
|
71
68
|
// Render info from `vfile.data.astro.frontmatter` as JS
|
|
@@ -10,15 +10,24 @@ const astroTagComponentImportRegex = /[\s,{]__astro_tag_component__[\s,}]/;
|
|
|
10
10
|
function vitePluginMdxPostprocess(astroConfig) {
|
|
11
11
|
return {
|
|
12
12
|
name: "@astrojs/mdx-postprocess",
|
|
13
|
-
transform
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
transform: {
|
|
14
|
+
filter: {
|
|
15
|
+
id: /\.mdx$/
|
|
16
|
+
},
|
|
17
|
+
handler(code, id) {
|
|
18
|
+
const fileInfo = getFileInfo(id, astroConfig);
|
|
19
|
+
const [imports, exports] = parse(code);
|
|
20
|
+
code = injectUnderscoreFragmentImport(code, imports);
|
|
21
|
+
code = injectMetadataExports(code, exports, fileInfo);
|
|
22
|
+
code = transformContentExport(code, exports);
|
|
23
|
+
code = annotateContentExport(
|
|
24
|
+
code,
|
|
25
|
+
id,
|
|
26
|
+
this.environment.name === "ssr" || this.environment.name === "prerender",
|
|
27
|
+
imports
|
|
28
|
+
);
|
|
29
|
+
return { code, map: null };
|
|
30
|
+
}
|
|
22
31
|
}
|
|
23
32
|
};
|
|
24
33
|
}
|
package/dist/vite-plugin-mdx.js
CHANGED
|
@@ -18,49 +18,58 @@ function vitePluginMdx(opts) {
|
|
|
18
18
|
resolved.plugins.splice(jsxPluginIndex, 1);
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
resolveId: {
|
|
22
|
+
filter: {
|
|
23
|
+
// Do not match sources that start with /
|
|
24
|
+
id: /^[^/]/
|
|
25
|
+
},
|
|
26
|
+
async handler(source, importer, options) {
|
|
27
|
+
if (importer?.endsWith(".mdx")) {
|
|
28
|
+
let resolved = await this.resolve(source, importer, options);
|
|
29
|
+
if (!resolved) resolved = await this.resolve("./" + source, importer, options);
|
|
30
|
+
return resolved;
|
|
31
|
+
}
|
|
26
32
|
}
|
|
27
33
|
},
|
|
28
34
|
// Override transform to alter code before MDX compilation
|
|
29
35
|
// ex. inject layouts
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
transform: {
|
|
37
|
+
filter: {
|
|
38
|
+
id: /\.mdx$/
|
|
39
|
+
},
|
|
40
|
+
async handler(code, id) {
|
|
41
|
+
const { frontmatter, content } = safeParseFrontmatter(code, id);
|
|
42
|
+
const vfile = new VFile({
|
|
43
|
+
value: content,
|
|
44
|
+
path: id,
|
|
45
|
+
data: {
|
|
46
|
+
astro: {
|
|
47
|
+
frontmatter
|
|
48
|
+
},
|
|
49
|
+
applyFrontmatterExport: {
|
|
50
|
+
srcDir: opts.srcDir
|
|
51
|
+
}
|
|
42
52
|
}
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
if (!processor) {
|
|
46
|
-
processor = createMdxProcessor(opts.mdxOptions, {
|
|
47
|
-
sourcemap: sourcemapEnabled,
|
|
48
|
-
experimentalHeadingIdCompat: opts.experimentalHeadingIdCompat
|
|
49
53
|
});
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
54
|
+
if (!processor) {
|
|
55
|
+
processor = createMdxProcessor(opts.mdxOptions, {
|
|
56
|
+
sourcemap: sourcemapEnabled
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
const compiled = await processor.process(vfile);
|
|
61
|
+
return {
|
|
62
|
+
code: String(compiled.value),
|
|
63
|
+
map: compiled.map,
|
|
64
|
+
meta: getMdxMeta(vfile)
|
|
65
|
+
};
|
|
66
|
+
} catch (e) {
|
|
67
|
+
const err = e;
|
|
68
|
+
err.name = "MDXError";
|
|
69
|
+
err.loc = { file: id, line: e.line, column: e.column };
|
|
70
|
+
Error.captureStackTrace(err);
|
|
71
|
+
throw err;
|
|
72
|
+
}
|
|
64
73
|
}
|
|
65
74
|
}
|
|
66
75
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/mdx",
|
|
3
3
|
"description": "Add support for MDX pages in your Astro site",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "5.0.0-beta.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"author": "withastro",
|
|
@@ -40,10 +40,10 @@
|
|
|
40
40
|
"source-map": "^0.7.6",
|
|
41
41
|
"unist-util-visit": "^5.0.0",
|
|
42
42
|
"vfile": "^6.0.3",
|
|
43
|
-
"@astrojs/markdown-remark": "
|
|
43
|
+
"@astrojs/markdown-remark": "7.0.0-beta.1"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
|
-
"astro": "^
|
|
46
|
+
"astro": "^6.0.0-alpha.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@types/estree": "^1.0.8",
|
|
@@ -59,14 +59,14 @@
|
|
|
59
59
|
"remark-rehype": "^11.1.2",
|
|
60
60
|
"remark-shiki-twoslash": "^3.1.3",
|
|
61
61
|
"remark-toc": "^9.0.0",
|
|
62
|
-
"shiki": "^3.
|
|
62
|
+
"shiki": "^3.20.0",
|
|
63
63
|
"unified": "^11.0.5",
|
|
64
|
-
"vite": "^
|
|
65
|
-
"astro
|
|
66
|
-
"astro": "
|
|
64
|
+
"vite": "^7.1.7",
|
|
65
|
+
"astro": "6.0.0-beta.1",
|
|
66
|
+
"astro-scripts": "0.0.14"
|
|
67
67
|
},
|
|
68
68
|
"engines": {
|
|
69
|
-
"node": "
|
|
69
|
+
"node": "^20.19.5 || >=22.12.0"
|
|
70
70
|
},
|
|
71
71
|
"publishConfig": {
|
|
72
72
|
"provenance": true
|