parent
1c40f6ed38
commit
b348ca6c9f
3 changed files with 11 additions and 1 deletions
5
.changeset/wise-icons-tell.md
Normal file
5
.changeset/wise-icons-tell.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Bugfix: allow dynamic importing of rehype plugins
|
|
@ -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;
|
||||
},
|
||||
|
|
|
@ -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'],
|
||||
},
|
||||
],
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue