summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.changeset/wise-icons-tell.md5
-rw-r--r--packages/astro/src/core/ssr/index.ts5
-rw-r--r--packages/astro/test/astro-markdown-plugins.test.js2
3 files changed, 11 insertions, 1 deletions
diff --git a/.changeset/wise-icons-tell.md b/.changeset/wise-icons-tell.md
new file mode 100644
index 000000000..f2d915237
--- /dev/null
+++ b/.changeset/wise-icons-tell.md
@@ -0,0 +1,5 @@
+---
+'astro': patch
+---
+
+Bugfix: allow dynamic importing of rehype plugins
diff --git a/packages/astro/src/core/ssr/index.ts b/packages/astro/src/core/ssr/index.ts
index af9702c9b..499039a56 100644
--- a/packages/astro/src/core/ssr/index.ts
+++ b/packages/astro/src/core/ssr/index.ts
@@ -209,9 +209,14 @@ export async function render(renderers: Renderer[], mod: ComponentInstance, ssrO
renderOpts = mdRender[1];
mdRender = mdRender[0];
}
+ // ['rehype-toc', opts]
if (typeof mdRender === 'string') {
({ default: mdRender } = await import(mdRender));
}
+ // [import('rehype-toc'), opts]
+ else if (mdRender instanceof Promise) {
+ ({ default: mdRender } = await mdRender);
+ }
const { code } = await mdRender(content, { ...renderOpts, ...(opts ?? {}) });
return code;
},
diff --git a/packages/astro/test/astro-markdown-plugins.test.js b/packages/astro/test/astro-markdown-plugins.test.js
index eab3f35a6..d3f20b073 100644
--- a/packages/astro/test/astro-markdown-plugins.test.js
+++ b/packages/astro/test/astro-markdown-plugins.test.js
@@ -15,7 +15,7 @@ describe('Astro Markdown plugins', () => {
markdownRemark,
{
remarkPlugins: ['remark-code-titles', ['rehype-autolink-headings', { behavior: 'prepend' }]],
- rehypePlugins: [['rehype-toc', { headings: ['h2', 'h3'] }], ['rehype-add-classes', { 'h1,h2,h3': 'title' }], 'rehype-slug'],
+ rehypePlugins: [[import('rehype-toc'), { headings: ['h2', 'h3'] }], ['rehype-add-classes', { 'h1,h2,h3': 'title' }], 'rehype-slug'],
},
],
},