diff options
author | 2022-12-20 23:08:15 +0100 | |
---|---|---|
committer | 2022-12-20 23:08:15 +0100 | |
commit | 2c65b433bf840a1bb93b0a1947df5949e33512ff (patch) | |
tree | 02314c6ee09b86d08e40367da647458806c932db /packages/integrations/mdx/src/plugins.ts | |
parent | a467139e169ad2eb7931e03004f1d658f7362e59 (diff) | |
download | astro-2c65b433bf840a1bb93b0a1947df5949e33512ff.tar.gz astro-2c65b433bf840a1bb93b0a1947df5949e33512ff.tar.zst astro-2c65b433bf840a1bb93b0a1947df5949e33512ff.zip |
MD/MDX collect headings refactor (#5654)
Diffstat (limited to 'packages/integrations/mdx/src/plugins.ts')
-rw-r--r-- | packages/integrations/mdx/src/plugins.ts | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/packages/integrations/mdx/src/plugins.ts b/packages/integrations/mdx/src/plugins.ts index 0ae148746..d46ab6cd4 100644 --- a/packages/integrations/mdx/src/plugins.ts +++ b/packages/integrations/mdx/src/plugins.ts @@ -1,3 +1,4 @@ +import { rehypeHeadingIds } from '@astrojs/markdown-remark'; import { nodeTypes } from '@mdx-js/mdx'; import type { PluggableList } from '@mdx-js/mdx/lib/core.js'; import type { Options as MdxRollupPluginOptions } from '@mdx-js/rollup'; @@ -10,7 +11,7 @@ import remarkGfm from 'remark-gfm'; import remarkSmartypants from 'remark-smartypants'; import type { Data, VFile } from 'vfile'; import { MdxOptions } from './index.js'; -import rehypeCollectHeadings from './rehype-collect-headings.js'; +import { rehypeInjectHeadingsExport } from './rehype-collect-headings.js'; import rehypeMetaString from './rehype-meta-string.js'; import remarkPrism from './remark-prism.js'; import remarkShiki from './remark-shiki.js'; @@ -153,8 +154,6 @@ export function getRehypePlugins( config: AstroConfig ): MdxRollupPluginOptions['rehypePlugins'] { let rehypePlugins: PluggableList = [ - // getHeadings() is guaranteed by TS, so we can't allow user to override - rehypeCollectHeadings, // ensure `data.meta` is preserved in `properties.metastring` for rehype syntax highlighters rehypeMetaString, // rehypeRaw allows custom syntax highlighters to work without added config @@ -175,7 +174,14 @@ export function getRehypePlugins( break; } - rehypePlugins = [...rehypePlugins, ...(mdxOptions.rehypePlugins ?? [])]; + rehypePlugins = [ + ...rehypePlugins, + ...(mdxOptions.rehypePlugins ?? []), + // getHeadings() is guaranteed by TS, so this must be included. + // We run `rehypeHeadingIds` _last_ to respect any custom IDs set by user plugins. + rehypeHeadingIds, + rehypeInjectHeadingsExport, + ]; return rehypePlugins; } |