File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed
packages/docusaurus/src/commands Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -259,6 +259,10 @@ export async function createCLIProgram({
259259 "keep the headings' casing, otherwise make all lowercase (default: false)" ,
260260 )
261261 . option ( '--overwrite' , 'overwrite existing heading IDs (default: false)' )
262+ . option (
263+ '--syntax <syntax>' ,
264+ 'heading ID syntax: "classic" ({#id}) or "mdx-comment" ({/* #id */}) (default: "classic")' ,
265+ )
262266 . action ( writeHeadingIds ) ;
263267
264268 cli . arguments ( '<command>' ) . action ( ( cmd ) => {
Original file line number Diff line number Diff line change @@ -61,11 +61,25 @@ async function getPathsToWatch(siteDir: string): Promise<string[]> {
6161 return plugins . flatMap ( ( plugin ) => plugin . getPathsToWatch ?.( ) ?? [ ] ) ;
6262}
6363
64+ // TODO Docusaurus v4 - Upgrade commander, use choices() API?
65+ function validateOptions ( options : WriteHeadingIDOptions ) {
66+ const validSyntaxValues : HeadingIdSyntax [ ] = [ 'classic' , 'mdx-comment' ] ;
67+ if ( options . syntax && ! [ 'classic' , 'mdx-comment' ] . includes ( options . syntax ) ) {
68+ throw new Error (
69+ `Invalid --syntax value "${
70+ options . syntax
71+ } ". Valid values: ${ validSyntaxValues . join ( ', ' ) } `,
72+ ) ;
73+ }
74+ }
75+
6476export async function writeHeadingIds (
6577 siteDirParam : string = '.' ,
6678 files : string [ ] = [ ] ,
6779 options : WriteHeadingIDOptions = { } ,
6880) : Promise < void > {
81+ validateOptions ( options ) ;
82+
6983 const siteDir = await fs . realpath ( siteDirParam ) ;
7084
7185 const patterns = files . length ? files : await getPathsToWatch ( siteDir ) ;
You can’t perform that action at this time.
0 commit comments