@astrojs/mdx 2.1.1 → 2.2.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.js CHANGED
@@ -1,8 +1,8 @@
1
+ import fs from "node:fs/promises";
2
+ import { fileURLToPath } from "node:url";
1
3
  import { markdownConfigDefaults, setVfileFrontmatter } from "@astrojs/markdown-remark";
2
4
  import astroJSXRenderer from "astro/jsx/renderer.js";
3
5
  import { parse as parseESM } from "es-module-lexer";
4
- import fs from "node:fs/promises";
5
- import { fileURLToPath } from "node:url";
6
6
  import { VFile } from "vfile";
7
7
  import { createMdxProcessor } from "./plugins.js";
8
8
  import {
@@ -103,7 +103,7 @@ function mdx(partialMdxOptions = {}) {
103
103
  const [moduleImports, moduleExports] = parseESM(code);
104
104
  const importsFromJSXRuntime = moduleImports.filter(({ n }) => n === "astro/jsx-runtime").map(({ ss, se }) => code.substring(ss, se));
105
105
  const hasFragmentImport = importsFromJSXRuntime.some(
106
- (statement) => /[\s,{](Fragment,|Fragment\s*})/.test(statement)
106
+ (statement) => /[\s,{](?:Fragment,|Fragment\s*\})/.test(statement)
107
107
  );
108
108
  if (!hasFragmentImport) {
109
109
  code = 'import { Fragment } from "astro/jsx-runtime"\n' + code;
package/dist/plugins.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  rehypeHeadingIds,
3
- remarkCollectImages,
4
- remarkPrism,
5
- remarkShiki
3
+ rehypePrism,
4
+ rehypeShiki,
5
+ remarkCollectImages
6
6
  } from "@astrojs/markdown-remark";
7
7
  import { createProcessor, nodeTypes } from "@mdx-js/mdx";
8
8
  import rehypeRaw from "rehype-raw";
@@ -41,20 +41,7 @@ function getRemarkPlugins(mdxOptions) {
41
41
  remarkPlugins.push(remarkSmartypants);
42
42
  }
43
43
  }
44
- remarkPlugins = [
45
- ...remarkPlugins,
46
- ...mdxOptions.remarkPlugins,
47
- remarkCollectImages,
48
- remarkImageToComponent
49
- ];
50
- if (!isPerformanceBenchmark) {
51
- if (mdxOptions.syntaxHighlight === "shiki") {
52
- remarkPlugins.push([remarkShiki, mdxOptions.shikiConfig]);
53
- }
54
- if (mdxOptions.syntaxHighlight === "prism") {
55
- remarkPlugins.push(remarkPrism);
56
- }
57
- }
44
+ remarkPlugins.push(...mdxOptions.remarkPlugins, remarkCollectImages, remarkImageToComponent);
58
45
  return remarkPlugins;
59
46
  }
60
47
  function getRehypePlugins(mdxOptions) {
@@ -64,15 +51,18 @@ function getRehypePlugins(mdxOptions) {
64
51
  // rehypeRaw allows custom syntax highlighters to work without added config
65
52
  [rehypeRaw, { passThrough: nodeTypes }]
66
53
  ];
67
- rehypePlugins = [
68
- ...rehypePlugins,
69
- ...mdxOptions.rehypePlugins,
70
- // getHeadings() is guaranteed by TS, so this must be included.
71
- // We run `rehypeHeadingIds` _last_ to respect any custom IDs set by user plugins.
72
- ...isPerformanceBenchmark ? [] : [rehypeHeadingIds, rehypeInjectHeadingsExport],
73
- // computed from `astro.data.frontmatter` in VFile data
74
- rehypeApplyFrontmatterExport
75
- ];
54
+ if (!isPerformanceBenchmark) {
55
+ if (mdxOptions.syntaxHighlight === "shiki") {
56
+ rehypePlugins.push([rehypeShiki, mdxOptions.shikiConfig]);
57
+ } else if (mdxOptions.syntaxHighlight === "prism") {
58
+ rehypePlugins.push(rehypePrism);
59
+ }
60
+ }
61
+ rehypePlugins.push(...mdxOptions.rehypePlugins);
62
+ if (!isPerformanceBenchmark) {
63
+ rehypePlugins.push(rehypeHeadingIds, rehypeInjectHeadingsExport);
64
+ }
65
+ rehypePlugins.push(rehypeApplyFrontmatterExport);
76
66
  if (mdxOptions.optimize) {
77
67
  const options = mdxOptions.optimize === true ? void 0 : mdxOptions.optimize;
78
68
  rehypePlugins.push([rehypeOptimizeStatic, options]);
package/dist/utils.js CHANGED
@@ -17,7 +17,7 @@ function getFileInfo(id, config) {
17
17
  let fileUrl;
18
18
  const isPage = fileId.includes("/pages/");
19
19
  if (isPage) {
20
- fileUrl = fileId.replace(/^.*?\/pages\//, sitePathname).replace(/(\/index)?\.mdx$/, "");
20
+ fileUrl = fileId.replace(/^.*?\/pages\//, sitePathname).replace(/(?:\/index)?\.mdx$/, "");
21
21
  } else if (url?.pathname.startsWith(config.root.pathname)) {
22
22
  fileUrl = url.pathname.slice(config.root.pathname.length);
23
23
  } else {
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": "2.1.1",
4
+ "version": "2.2.0",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",
7
7
  "author": "withastro",
@@ -41,7 +41,7 @@
41
41
  "source-map": "^0.7.4",
42
42
  "unist-util-visit": "^5.0.0",
43
43
  "vfile": "^6.0.1",
44
- "@astrojs/markdown-remark": "4.2.1"
44
+ "@astrojs/markdown-remark": "4.3.0"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "astro": "^4.0.0"
@@ -52,22 +52,20 @@
52
52
  "@types/mdast": "^4.0.3",
53
53
  "@types/mocha": "^10.0.4",
54
54
  "@types/yargs-parser": "^21.0.3",
55
- "chai": "^4.3.7",
56
55
  "cheerio": "1.0.0-rc.12",
57
56
  "linkedom": "^0.16.4",
58
57
  "mdast-util-mdx": "^3.0.0",
59
58
  "mdast-util-to-string": "^4.0.0",
60
- "mocha": "^10.2.0",
61
59
  "reading-time": "^1.5.0",
62
60
  "rehype-mathjax": "^5.0.0",
63
- "rehype-pretty-code": "^0.10.2",
61
+ "rehype-pretty-code": "^0.13.0",
64
62
  "remark-math": "^6.0.0",
65
63
  "remark-rehype": "^11.0.0",
66
64
  "remark-shiki-twoslash": "^3.1.3",
67
65
  "remark-toc": "^9.0.0",
68
66
  "unified": "^11.0.4",
69
- "vite": "^5.0.12",
70
- "astro": "4.2.7",
67
+ "vite": "^5.1.4",
68
+ "astro": "4.5.0",
71
69
  "astro-scripts": "0.0.14"
72
70
  },
73
71
  "engines": {
@@ -80,7 +78,6 @@
80
78
  "build": "astro-scripts build \"src/**/*.ts\" && tsc",
81
79
  "build:ci": "astro-scripts build \"src/**/*.ts\"",
82
80
  "dev": "astro-scripts dev \"src/**/*.ts\"",
83
- "test": "mocha --exit --timeout 20000",
84
- "test:match": "mocha --timeout 20000 -g"
81
+ "test": "astro-scripts test --timeout 70000 \"test/**/*.test.js\""
85
82
  }
86
83
  }