@@ -4,7 +4,6 @@ import tailwind from "@astrojs/tailwind";
44import starlightDocSearch from "@astrojs/starlight-docsearch" ;
55import starlightImageZoom from "starlight-image-zoom" ;
66import liveCode from "astro-live-code" ;
7- import rehypeSlug from "rehype-slug" ;
87import rehypeMermaid from "rehype-mermaid" ;
98import rehypeAutolinkHeadings , {
109 type Options as rehypeAutolinkHeadingsOptions ,
@@ -17,7 +16,7 @@ import icon from "astro-icon";
1716import sitemap from "@astrojs/sitemap" ;
1817import react from "@astrojs/react" ;
1918import rehypeTitleFigure from "rehype-title-figure" ;
20- import { visit } from "unist-util-visit " ;
19+ import rehypeHeadingSlugs from "./plugins/rehype/heading-slugs " ;
2120
2221const runLinkCheck = process . env . RUN_LINK_CHECK || false ;
2322
@@ -71,30 +70,6 @@ const autolinkConfig: rehypeAutolinkHeadingsOptions = {
7170 content : ( ) => [ AnchorLinkIcon ] ,
7271} ;
7372
74- // # foo {/*bar*/} = <a id="bar">foo</a>
75- function rehypeCustomHeadingId ( ) {
76- return function ( tree : any ) {
77- visit ( tree , "element" , function ( element : any ) {
78- if ( / ^ h [ 1 - 6 ] $ / . test ( element . tagName ) ) {
79- const last = element . children . at ( - 1 ) ;
80-
81- if (
82- last . type === "mdxTextExpression" &&
83- last . value . startsWith ( "/*" ) &&
84- last . value . endsWith ( "*/" )
85- ) {
86- const id = last . value . slice ( 2 , - 2 ) . trim ( ) ;
87- element . properties . id = id ;
88-
89- const text = element . children . at ( - 2 ) ;
90- text . value = text . value . trimEnd ( ) ;
91- element . children . with ( - 2 , text ) ;
92- }
93- }
94- } ) ;
95- } ;
96- }
97-
9873// https://astro.build/config
9974export default defineConfig ( {
10075 site : "https://developers.cloudflare.com" ,
@@ -120,8 +95,7 @@ export default defineConfig({
12095 rel : [ "noopener" ] ,
12196 } ,
12297 ] ,
123- rehypeCustomHeadingId ,
124- rehypeSlug ,
98+ rehypeHeadingSlugs ,
12599 [ rehypeAutolinkHeadings , autolinkConfig ] ,
126100 // @ts -expect-error TODO: fix types
127101 rehypeTitleFigure ,
0 commit comments