@@ -11,16 +11,37 @@ import {
1111 safeGlobby ,
1212 writeMarkdownHeadingId ,
1313 type WriteHeadingIDOptions ,
14+ type HeadingIdSyntax ,
1415} from '@docusaurus/utils' ;
1516import { loadContext } from '../server/site' ;
1617import { initPlugins } from '../server/plugins/init' ;
1718
19+ function inferFallbackSyntax ( _filepath : string ) : HeadingIdSyntax {
20+ // TODO Docusaurus v4 - infer the syntax based on the file extensions?
21+ // This is not ideal because we have many ways to define the syntax
22+ // (front matter "format", siteConfig.markdown.format etc...)
23+ // but probably good enough for now
24+
25+ // Until then, we default to the classic syntax
26+ // The mdx-comment syntax is opt-in
27+ return 'classic' ;
28+ }
29+
30+ function getHeadingIdSyntax ( filepath : string , options ?: WriteHeadingIDOptions ) {
31+ return options ?. syntax ?? inferFallbackSyntax ( filepath ) ;
32+ }
33+
1834async function transformMarkdownFile (
1935 filepath : string ,
2036 options ?: WriteHeadingIDOptions ,
2137) : Promise < string | undefined > {
2238 const content = await fs . readFile ( filepath , 'utf8' ) ;
23- const updatedContent = writeMarkdownHeadingId ( content , options ) ;
39+
40+ const syntax = getHeadingIdSyntax ( filepath , options ) ;
41+ const updatedContent = writeMarkdownHeadingId ( content , {
42+ ...options ,
43+ syntax,
44+ } ) ;
2445 if ( content !== updatedContent ) {
2546 await fs . writeFile ( filepath , updatedContent ) ;
2647 return filepath ;
0 commit comments