11import type { RehypePlugin } from "@astrojs/markdown-remark" ;
22import type { AstroIntegration , AstroUserConfig } from "astro" ;
3- import type { Options } from "rehype-class-names" ;
3+ import type { Options as AutolinkHeadingsOptions } from "rehype-autolink-headings" ;
4+ import type { Options as ClassNamesOptions } from "rehype-class-names" ;
45import type {
56 LegacyAsyncImporter ,
67 LegacySharedOptions ,
@@ -15,21 +16,23 @@ import path from "node:path";
1516import nodeUrl from "node:url" ;
1617import util from "node:util" ;
1718
19+ import { rehypeHeadingIds } from "@astrojs/markdown-remark" ;
1820import mdx from "@astrojs/mdx" ;
19- // @ts -expect-error There's no type declaration but it exists.
21+ // @ts -expect-error - There's no type declaration but it exists.
2022import remarkA11yEmoji from "@fec/remark-a11y-emoji" ;
2123import { addExtension , createFilter , dataToEsm } from "@rollup/pluginutils" ;
2224import compress from "astro-compress" ;
2325import { walk } from "estree-walker" ;
2426import findCacheDirectory from "find-cache-dir" ;
2527import gifsicle from "gifsicle" ;
2628import { customAlphabet } from "nanoid" ;
29+ import rehypeAutolinkHeadings from "rehype-autolink-headings" ;
2730import rehypeClassNames from "rehype-class-names" ;
2831import sharp from "sharp" ;
2932sharp . cache ( false ) ;
3033
3134//==================================================
32- // Astro - Shiki and rehype
35+ // Astro - Markdown transformers and plugins
3336//==================================================
3437
3538const classNamesTransformer : ShikiTransformer = {
@@ -41,7 +44,7 @@ const classNamesTransformer: ShikiTransformer = {
4144 node . properties . class = "block-code-token" ;
4245 }
4346} ;
44- const classNamesPlugin : [ RehypePlugin , Options ] = [
47+ const classNamesPlugin : [ RehypePlugin , ClassNamesOptions ] = [
4548 rehypeClassNames ,
4649 { ":not(pre) > code" : "inline-code" }
4750] ;
@@ -103,6 +106,11 @@ const themeTransformer: ShikiTransformer = {
103106 }
104107} ;
105108
109+ const autolinkHeadingsPlugin : [ RehypePlugin , AutolinkHeadingsOptions ] = [
110+ rehypeAutolinkHeadings ,
111+ { behavior : "wrap" }
112+ ] ;
113+
106114//==================================================
107115// Astro - Integrations
108116//==================================================
@@ -402,7 +410,7 @@ export default <AstroUserConfig>{
402410 transformers : [ classNamesTransformer , themeTransformer ]
403411 } ,
404412 remarkPlugins : [ remarkA11yEmoji ] ,
405- rehypePlugins : [ classNamesPlugin ]
413+ rehypePlugins : [ classNamesPlugin , rehypeHeadingIds , autolinkHeadingsPlugin ]
406414 } ,
407415 integrations : [ mdx ( ) , optimizeImagesIntegration , compress ( { Image : false } ) ] ,
408416 vite : { css : { preprocessorOptions : { scss } } , plugins : [ generateIdsPlugin ] }
0 commit comments