Skip to content

Commit 16424d0

Browse files
committed
wire to cli
1 parent d5cdc93 commit 16424d0

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

packages/docusaurus/src/commands/writeHeadingIds.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,37 @@ import {
1111
safeGlobby,
1212
writeMarkdownHeadingId,
1313
type WriteHeadingIDOptions,
14+
type HeadingIdSyntax,
1415
} from '@docusaurus/utils';
1516
import {loadContext} from '../server/site';
1617
import {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+
1834
async 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

Comments
 (0)