Skip to content

Commit 234b9ea

Browse files
committed
wire to cli
1 parent 16424d0 commit 234b9ea

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

packages/docusaurus/src/commands/cli.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff 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) => {

packages/docusaurus/src/commands/writeHeadingIds.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
6476
export 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);

0 commit comments

Comments
 (0)