summaryrefslogtreecommitdiff
path: root/packages/integrations/mdx
diff options
context:
space:
mode:
Diffstat (limited to 'packages/integrations/mdx')
-rw-r--r--packages/integrations/mdx/CHANGELOG.md14
-rw-r--r--packages/integrations/mdx/README.md6
-rw-r--r--packages/integrations/mdx/package.json52
-rw-r--r--packages/integrations/mdx/src/index.ts7
-rw-r--r--packages/integrations/mdx/src/plugins.ts8
-rw-r--r--packages/integrations/mdx/src/remark-images-to-component.ts2
-rw-r--r--packages/integrations/mdx/src/utils.ts4
-rw-r--r--packages/integrations/mdx/test/fixtures/mdx-frontmatter-injection/src/pages/glob.json.js8
-rw-r--r--packages/integrations/mdx/test/fixtures/mdx-frontmatter/src/pages/glob.json.js11
-rw-r--r--packages/integrations/mdx/test/fixtures/mdx-get-headings/src/pages/pages.json.js15
-rw-r--r--packages/integrations/mdx/test/fixtures/mdx-infinite-loop/package.json2
-rw-r--r--packages/integrations/mdx/test/fixtures/mdx-url-export/src/pages/pages.json.js11
-rw-r--r--packages/integrations/mdx/test/fixtures/mdx-vite-env-vars/src/pages/frontmatter.json.js6
-rw-r--r--packages/integrations/mdx/test/mdx-astro-markdown-remarkRehype.test.js2
-rw-r--r--packages/integrations/mdx/test/mdx-math.test.js2
15 files changed, 74 insertions, 76 deletions
diff --git a/packages/integrations/mdx/CHANGELOG.md b/packages/integrations/mdx/CHANGELOG.md
index 80febcb54..11632d110 100644
--- a/packages/integrations/mdx/CHANGELOG.md
+++ b/packages/integrations/mdx/CHANGELOG.md
@@ -1,5 +1,19 @@
# @astrojs/mdx
+## 2.0.0-beta.0
+
+### Major Changes
+
+- [#9138](https://github.com/withastro/astro/pull/9138) [`abf601233`](https://github.com/withastro/astro/commit/abf601233f8188d118a8cb063c777478d8d9f1a3) Thanks [@bluwy](https://github.com/bluwy)! - Updates the unified, remark, and rehype dependencies to latest. Make sure to update your custom remark and rehype plugins as well to be compatible with the latest versions.
+
+ **Potentially breaking change:** The default value of `markdown.remarkRehype.footnoteBackLabel` is changed from `"Back to content"` to `"Back to reference 1"`. See the `mdast-util-to-hast` [commit](https://github.com/syntax-tree/mdast-util-to-hast/commit/56c88e45690be138fad9f0bf367b939d09816863) for more information.
+
+### Patch Changes
+
+- Updated dependencies [[`abf601233`](https://github.com/withastro/astro/commit/abf601233f8188d118a8cb063c777478d8d9f1a3), [`6201bbe96`](https://github.com/withastro/astro/commit/6201bbe96c2a083fb201e4a43a9bd88499821a3e), [`cdabf6ef0`](https://github.com/withastro/astro/commit/cdabf6ef02be7220fd2b6bdcef924ceca089381e), [`addb57c8e`](https://github.com/withastro/astro/commit/addb57c8e80b7b67ec61224666f3a1db5c44410c), [`1c48ed286`](https://github.com/withastro/astro/commit/1c48ed286538ab9e354eca4e4dcd7c6385c96721), [`37697a2c5`](https://github.com/withastro/astro/commit/37697a2c5511572dc29c0a4ea46f90c2f62be8e6), [`bd0c2e9ae`](https://github.com/withastro/astro/commit/bd0c2e9ae3389a9d3085050c1e8134ae98dff299), [`c7953645e`](https://github.com/withastro/astro/commit/c7953645eeaaf9e87c6db4494b0023d2c1878ff0), [`0fe3a7ed5`](https://github.com/withastro/astro/commit/0fe3a7ed5d7bb1a9fce1623e84ba14104b51223c), [`710be505c`](https://github.com/withastro/astro/commit/710be505c9ddf416e77a75343d8cae9c497d72c6), [`153a5abb9`](https://github.com/withastro/astro/commit/153a5abb905042ac68b712514dc9ec387d3e6b17)]:
+ - @astrojs/markdown-remark@4.0.0-beta.0
+ - astro@4.0.0-beta.0
+
## 1.1.5
### Patch Changes
diff --git a/packages/integrations/mdx/README.md b/packages/integrations/mdx/README.md
index df0458ce9..150ada5e8 100644
--- a/packages/integrations/mdx/README.md
+++ b/packages/integrations/mdx/README.md
@@ -83,11 +83,7 @@ You can configure how your MDX is rendered with the following options:
### Options inherited from Markdown config
-All [`markdown` configuration options](https://docs.astro.build/en/reference/configuration-reference/#markdown-options) except `drafts` can be configured separately in the MDX integration. This includes remark and rehype plugins, syntax highlighting, and more. Options will default to those in your Markdown config ([see the `extendMarkdownConfig` option](#extendmarkdownconfig) to modify this).
-
-:::note
-There is no separate MDX configuration for [including pages marked as draft in the build](https://docs.astro.build/en/reference/configuration-reference/#markdowndrafts). This Markdown setting will be respected by both Markdown and MDX files and cannot be overridden for MDX files specifically.
-:::
+All [`markdown` configuration options](https://docs.astro.build/en/reference/configuration-reference/#markdown-options) can be configured separately in the MDX integration. This includes remark and rehype plugins, syntax highlighting, and more. Options will default to those in your Markdown config ([see the `extendMarkdownConfig` option](#extendmarkdownconfig) to modify this).
```js
// astro.config.mjs
diff --git a/packages/integrations/mdx/package.json b/packages/integrations/mdx/package.json
index f9e22d58c..3f5b6d559 100644
--- a/packages/integrations/mdx/package.json
+++ b/packages/integrations/mdx/package.json
@@ -1,7 +1,7 @@
{
"name": "@astrojs/mdx",
"description": "Add support for MDX pages in your Astro site",
- "version": "1.1.5",
+ "version": "2.0.0-beta.0",
"type": "module",
"types": "./dist/index.d.ts",
"author": "withastro",
@@ -35,47 +35,47 @@
},
"dependencies": {
"@astrojs/markdown-remark": "workspace:*",
- "@mdx-js/mdx": "^2.3.0",
- "acorn": "^8.10.0",
- "es-module-lexer": "^1.3.0",
- "estree-util-visit": "^1.2.1",
+ "@mdx-js/mdx": "^3.0.0",
+ "acorn": "^8.11.2",
+ "es-module-lexer": "^1.4.1",
+ "estree-util-visit": "^2.0.0",
"github-slugger": "^2.0.0",
"gray-matter": "^4.0.3",
- "hast-util-to-html": "^8.0.4",
+ "hast-util-to-html": "^9.0.0",
"kleur": "^4.1.4",
- "rehype-raw": "^6.1.1",
- "remark-gfm": "^3.0.1",
+ "rehype-raw": "^7.0.0",
+ "remark-gfm": "^4.0.0",
"remark-smartypants": "^2.0.0",
"source-map": "^0.7.4",
- "unist-util-visit": "^4.1.2",
- "vfile": "^5.3.7"
+ "unist-util-visit": "^5.0.0",
+ "vfile": "^6.0.1"
},
"peerDependencies": {
- "astro": "^3.0.0"
+ "astro": "^4.0.0-beta.0"
},
"devDependencies": {
- "@types/chai": "^4.3.5",
- "@types/estree": "^1.0.1",
- "@types/mdast": "^3.0.12",
- "@types/mocha": "^10.0.1",
- "@types/yargs-parser": "^21.0.0",
+ "@types/chai": "^4.3.10",
+ "@types/estree": "^1.0.5",
+ "@types/mdast": "^4.0.3",
+ "@types/mocha": "^10.0.4",
+ "@types/yargs-parser": "^21.0.3",
"astro": "workspace:*",
"astro-scripts": "workspace:*",
"chai": "^4.3.7",
"cheerio": "1.0.0-rc.12",
- "linkedom": "^0.15.1",
- "mdast-util-mdx": "^2.0.1",
- "mdast-util-to-string": "^3.2.0",
+ "linkedom": "^0.16.4",
+ "mdast-util-mdx": "^3.0.0",
+ "mdast-util-to-string": "^4.0.0",
"mocha": "^10.2.0",
"reading-time": "^1.5.0",
- "rehype-mathjax": "^4.0.3",
- "rehype-pretty-code": "^0.10.0",
- "remark-math": "^5.1.1",
- "remark-rehype": "^10.1.0",
+ "rehype-mathjax": "^5.0.0",
+ "rehype-pretty-code": "^0.10.2",
+ "remark-math": "^6.0.0",
+ "remark-rehype": "^11.0.0",
"remark-shiki-twoslash": "^3.1.3",
- "remark-toc": "^8.0.1",
- "unified": "^10.1.2",
- "vite": "^4.4.9"
+ "remark-toc": "^9.0.0",
+ "unified": "^11.0.4",
+ "vite": "^5.0.0"
},
"engines": {
"node": ">=18.14.1"
diff --git a/packages/integrations/mdx/src/index.ts b/packages/integrations/mdx/src/index.ts
index fd330625e..3fc00a723 100644
--- a/packages/integrations/mdx/src/index.ts
+++ b/packages/integrations/mdx/src/index.ts
@@ -1,8 +1,8 @@
import { markdownConfigDefaults, setVfileFrontmatter } from '@astrojs/markdown-remark';
-import type { PluggableList } from '@mdx-js/mdx/lib/core.js';
import type { AstroIntegration, ContentEntryType, HookParameters, SSRError } from 'astro';
import astroJSXRenderer from 'astro/jsx/renderer.js';
import { parse as parseESM } from 'es-module-lexer';
+import type { PluggableList } from 'unified';
import fs from 'node:fs/promises';
import { fileURLToPath } from 'node:url';
import type { Options as RemarkRehypeOptions } from 'remark-rehype';
@@ -190,7 +190,10 @@ export default function mdx(partialMdxOptions: Partial<MdxOptions> = {}): AstroI
componentsCode += ' }';
// Make `Content` the default export so we can wrap `MDXContent` and pass in `Fragment`
- code = code.replace('export default MDXContent;', '');
+ code = code.replace(
+ 'export default function MDXContent',
+ 'function MDXContent'
+ );
code += `\nexport const Content = (props = {}) => MDXContent({
...props,
components: ${componentsCode},
diff --git a/packages/integrations/mdx/src/plugins.ts b/packages/integrations/mdx/src/plugins.ts
index 3286a9fd8..e6584aacf 100644
--- a/packages/integrations/mdx/src/plugins.ts
+++ b/packages/integrations/mdx/src/plugins.ts
@@ -5,12 +5,11 @@ import {
remarkShiki,
} from '@astrojs/markdown-remark';
import { createProcessor, nodeTypes } from '@mdx-js/mdx';
-import type { PluggableList } from '@mdx-js/mdx/lib/core.js';
import rehypeRaw from 'rehype-raw';
import remarkGfm from 'remark-gfm';
import remarkSmartypants from 'remark-smartypants';
import { SourceMapGenerator } from 'source-map';
-import type { Processor } from 'unified';
+import type { PluggableList } from 'unified';
import type { MdxOptions } from './index.js';
import { recmaInjectImportMetaEnv } from './recma-inject-import-meta-env.js';
import { rehypeApplyFrontmatterExport } from './rehype-apply-frontmatter-export.js';
@@ -27,10 +26,7 @@ interface MdxProcessorExtraOptions {
importMetaEnv: Record<string, any>;
}
-export function createMdxProcessor(
- mdxOptions: MdxOptions,
- extraOptions: MdxProcessorExtraOptions
-): Processor {
+export function createMdxProcessor(mdxOptions: MdxOptions, extraOptions: MdxProcessorExtraOptions) {
return createProcessor({
remarkPlugins: getRemarkPlugins(mdxOptions),
rehypePlugins: getRehypePlugins(mdxOptions),
diff --git a/packages/integrations/mdx/src/remark-images-to-component.ts b/packages/integrations/mdx/src/remark-images-to-component.ts
index f83f5d76a..810056def 100644
--- a/packages/integrations/mdx/src/remark-images-to-component.ts
+++ b/packages/integrations/mdx/src/remark-images-to-component.ts
@@ -15,7 +15,7 @@ export function remarkImageToComponent() {
const importsStatements: MdxjsEsm[] = [];
const importedImages = new Map<string, string>();
- visit(tree, 'image', (node: Image, index: number | null, parent: Parent | null) => {
+ visit(tree, 'image', (node: Image, index: number | undefined, parent: Parent | null) => {
// Use the imagePaths set from the remark-collect-images so we don't have to duplicate the logic for
// checking if an image should be imported or not
if (file.data.imagePaths?.has(node.url)) {
diff --git a/packages/integrations/mdx/src/utils.ts b/packages/integrations/mdx/src/utils.ts
index 3425c50e3..a5b198116 100644
--- a/packages/integrations/mdx/src/utils.ts
+++ b/packages/integrations/mdx/src/utils.ts
@@ -1,10 +1,10 @@
-import type { PluggableList } from '@mdx-js/mdx/lib/core.js';
import type { Options as AcornOpts } from 'acorn';
import { parse } from 'acorn';
import type { AstroConfig, SSRError } from 'astro';
import matter from 'gray-matter';
import { bold, yellow } from 'kleur/colors';
import type { MdxjsEsm } from 'mdast-util-mdx';
+import type { PluggableList } from 'unified';
function appendForwardSlash(path: string) {
return path.endsWith('/') ? path : path + '/';
@@ -75,8 +75,8 @@ export function jsToTreeNode(
type: 'mdxjsEsm',
value: '',
data: {
+ // @ts-expect-error `parse` return types is incompatible but it should work in runtime
estree: {
- body: [],
...parse(jsString, acornOpts),
type: 'Program',
sourceType: 'module',
diff --git a/packages/integrations/mdx/test/fixtures/mdx-frontmatter-injection/src/pages/glob.json.js b/packages/integrations/mdx/test/fixtures/mdx-frontmatter-injection/src/pages/glob.json.js
index b73cd234d..63248dc56 100644
--- a/packages/integrations/mdx/test/fixtures/mdx-frontmatter-injection/src/pages/glob.json.js
+++ b/packages/integrations/mdx/test/fixtures/mdx-frontmatter-injection/src/pages/glob.json.js
@@ -1,6 +1,6 @@
-export async function get() {
+export async function GET() {
const docs = await import.meta.glob('./*.mdx', { eager: true });
- return {
- body: JSON.stringify(Object.values(docs).map(doc => doc.frontmatter)),
- }
+ return new Response(
+ JSON.stringify(Object.values(docs).map(doc => doc.frontmatter))
+ );
}
diff --git a/packages/integrations/mdx/test/fixtures/mdx-frontmatter/src/pages/glob.json.js b/packages/integrations/mdx/test/fixtures/mdx-frontmatter/src/pages/glob.json.js
index a1d6a4ac4..d82d9f770 100644
--- a/packages/integrations/mdx/test/fixtures/mdx-frontmatter/src/pages/glob.json.js
+++ b/packages/integrations/mdx/test/fixtures/mdx-frontmatter/src/pages/glob.json.js
@@ -1,9 +1,6 @@
-export async function get() {
+export async function GET() {
const mdxPages = await import.meta.glob('./*.mdx', { eager: true });
-
- return {
- body: JSON.stringify({
- titles: Object.values(mdxPages ?? {}).map(v => v?.frontmatter?.title),
- })
- }
+ return Response.json({
+ titles: Object.values(mdxPages ?? {}).map((v) => v?.frontmatter?.title),
+ });
}
diff --git a/packages/integrations/mdx/test/fixtures/mdx-get-headings/src/pages/pages.json.js b/packages/integrations/mdx/test/fixtures/mdx-get-headings/src/pages/pages.json.js
index 940e5c141..e57192c61 100644
--- a/packages/integrations/mdx/test/fixtures/mdx-get-headings/src/pages/pages.json.js
+++ b/packages/integrations/mdx/test/fixtures/mdx-get-headings/src/pages/pages.json.js
@@ -1,11 +1,8 @@
-export async function get() {
+export async function GET() {
const mdxPages = await import.meta.glob('./*.mdx', { eager: true });
-
- return {
- body: JSON.stringify({
- headingsByPage: Object.fromEntries(
- Object.entries(mdxPages ?? {}).map(([k, v]) => [k, v?.getHeadings()])
- ),
- }),
- }
+ return Response.json({
+ headingsByPage: Object.fromEntries(
+ Object.entries(mdxPages ?? {}).map(([k, v]) => [k, v?.getHeadings()])
+ ),
+ });
}
diff --git a/packages/integrations/mdx/test/fixtures/mdx-infinite-loop/package.json b/packages/integrations/mdx/test/fixtures/mdx-infinite-loop/package.json
index d2fb7a75d..a00e19d5b 100644
--- a/packages/integrations/mdx/test/fixtures/mdx-infinite-loop/package.json
+++ b/packages/integrations/mdx/test/fixtures/mdx-infinite-loop/package.json
@@ -6,6 +6,6 @@
"@astrojs/mdx": "workspace:*",
"@astrojs/preact": "workspace:*",
"astro": "workspace:*",
- "preact": "^10.17.1"
+ "preact": "^10.19.2"
}
}
diff --git a/packages/integrations/mdx/test/fixtures/mdx-url-export/src/pages/pages.json.js b/packages/integrations/mdx/test/fixtures/mdx-url-export/src/pages/pages.json.js
index 36b6f7af6..02cff64a8 100644
--- a/packages/integrations/mdx/test/fixtures/mdx-url-export/src/pages/pages.json.js
+++ b/packages/integrations/mdx/test/fixtures/mdx-url-export/src/pages/pages.json.js
@@ -1,9 +1,6 @@
-export async function get() {
+export async function GET() {
const mdxPages = await import.meta.glob('./*.mdx', { eager: true });
-
- return {
- body: JSON.stringify({
- urls: Object.values(mdxPages ?? {}).map(v => v?.url),
- })
- }
+ return Response.json({
+ urls: Object.values(mdxPages ?? {}).map((v) => v?.url),
+ });
}
diff --git a/packages/integrations/mdx/test/fixtures/mdx-vite-env-vars/src/pages/frontmatter.json.js b/packages/integrations/mdx/test/fixtures/mdx-vite-env-vars/src/pages/frontmatter.json.js
index ce3cf81e5..152285b9c 100644
--- a/packages/integrations/mdx/test/fixtures/mdx-vite-env-vars/src/pages/frontmatter.json.js
+++ b/packages/integrations/mdx/test/fixtures/mdx-vite-env-vars/src/pages/frontmatter.json.js
@@ -1,7 +1,5 @@
import { frontmatter } from './vite-env-vars.mdx';
-export function get() {
- return {
- body: JSON.stringify(frontmatter),
- }
+export function GET() {
+ return Response.json(frontmatter);
}
diff --git a/packages/integrations/mdx/test/mdx-astro-markdown-remarkRehype.test.js b/packages/integrations/mdx/test/mdx-astro-markdown-remarkRehype.test.js
index ddcce4ba5..eab2c61b0 100644
--- a/packages/integrations/mdx/test/mdx-astro-markdown-remarkRehype.test.js
+++ b/packages/integrations/mdx/test/mdx-astro-markdown-remarkRehype.test.js
@@ -79,7 +79,7 @@ describe('MDX with Astro Markdown remark-rehype config', () => {
expect(document.querySelector('#footnote-label').textContent).to.equal('Catatan kaki');
expect(document.querySelector('.data-footnote-backref').getAttribute('aria-label')).to.equal(
- 'Back to content'
+ 'Back to reference 1'
);
});
});
diff --git a/packages/integrations/mdx/test/mdx-math.test.js b/packages/integrations/mdx/test/mdx-math.test.js
index f39ea42c8..52ee94a46 100644
--- a/packages/integrations/mdx/test/mdx-math.test.js
+++ b/packages/integrations/mdx/test/mdx-math.test.js
@@ -4,7 +4,7 @@ import { parseHTML } from 'linkedom';
import { loadFixture } from '../../../astro/test/test-utils.js';
import remarkMath from 'remark-math';
import rehypeMathjaxSvg from 'rehype-mathjax';
-import rehypeMathjaxChtml from 'rehype-mathjax/chtml.js';
+import rehypeMathjaxChtml from 'rehype-mathjax/chtml';
const FIXTURE_ROOT = new URL('./fixtures/mdx-math/', import.meta.url);