@docusaurus/core 4.0.0-canary-6971 → 4.0.0-canary-6973
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/commands/cli.js
CHANGED
|
@@ -141,7 +141,7 @@ async function createCLIProgram({ cli, cliArgs, siteDir, config, }) {
|
|
|
141
141
|
cli
|
|
142
142
|
.command('write-heading-ids [siteDir] [files...]')
|
|
143
143
|
.description('Generate heading ids in Markdown content.')
|
|
144
|
-
.
|
|
144
|
+
.addOption(new commander_1.Option('--syntax <syntax>', 'heading ID syntax: "classic" ({#id}) or "mdx-comment" ({/* #id */}) (default: "classic" for files compiled as CommonMark, "mdx-comment" for files compiled as MDX)').choices(writeHeadingIds_1.HeadingIdSyntaxes))
|
|
145
145
|
.option('--migrate', 'migrate existing heading IDs to the target --syntax, if they are using a different syntax (default: false)')
|
|
146
146
|
.option('--overwrite', 'overwrite existing heading IDs, re-generate them from the heading text (default: false)')
|
|
147
147
|
.option('--maintain-case', "keep the headings' casing, otherwise make all lowercase (default: false)")
|
|
@@ -5,4 +5,5 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import { type WriteHeadingIDOptions } from '@docusaurus/utils';
|
|
8
|
+
export declare const HeadingIdSyntaxes: ["classic", "mdx-comment"];
|
|
8
9
|
export declare function writeHeadingIds(siteDirParam?: string, files?: string[], options?: WriteHeadingIDOptions): Promise<void>;
|
|
@@ -6,29 +6,37 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.HeadingIdSyntaxes = void 0;
|
|
9
10
|
exports.writeHeadingIds = writeHeadingIds;
|
|
10
11
|
const tslib_1 = require("tslib");
|
|
12
|
+
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
11
13
|
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
12
14
|
const utils_1 = require("@docusaurus/utils");
|
|
13
15
|
const glob_1 = require("@docusaurus/glob");
|
|
14
16
|
const fs_1 = require("@docusaurus/fs");
|
|
15
17
|
const site_1 = require("../server/site");
|
|
16
18
|
const init_1 = require("../server/plugins/init");
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
19
|
+
exports.HeadingIdSyntaxes = [
|
|
20
|
+
'classic',
|
|
21
|
+
'mdx-comment',
|
|
22
|
+
];
|
|
23
|
+
/**
|
|
24
|
+
* Infer the heading ID syntax that compiles for a given file:
|
|
25
|
+
* - `classic` ({#id}) for files compiled as CommonMark
|
|
26
|
+
* - `mdx-comment` ({/* #id * /}) for files compiled as MDX
|
|
27
|
+
*
|
|
28
|
+
* The front matter `format` is not taken into account, but users can still
|
|
29
|
+
* use the `--syntax` option to target a specific syntax.
|
|
30
|
+
*/
|
|
31
|
+
function inferFallbackSyntax(filepath, markdownConfig) {
|
|
32
|
+
const isCommonMark = markdownConfig.format === 'detect'
|
|
33
|
+
? node_path_1.default.extname(filepath) === '.md'
|
|
34
|
+
: markdownConfig.format === 'md';
|
|
35
|
+
return isCommonMark ? 'classic' : 'mdx-comment';
|
|
28
36
|
}
|
|
29
|
-
async function transformMarkdownFile(filepath, options) {
|
|
37
|
+
async function transformMarkdownFile(filepath, markdownConfig, options) {
|
|
30
38
|
const content = await fs_1.fs.readFile(filepath, 'utf8');
|
|
31
|
-
const syntax =
|
|
39
|
+
const syntax = options.syntax ?? inferFallbackSyntax(filepath, markdownConfig);
|
|
32
40
|
const updatedContent = (0, utils_1.writeMarkdownHeadingId)(content, {
|
|
33
41
|
...options,
|
|
34
42
|
syntax,
|
|
@@ -49,16 +57,14 @@ async function globMarkdownFiles(patterns) {
|
|
|
49
57
|
* not belong to a content plugin. For example ./README.md should not be
|
|
50
58
|
* transformed
|
|
51
59
|
*/
|
|
52
|
-
async function getPathsToWatch(
|
|
53
|
-
const context = await (0, site_1.loadContext)({ siteDir });
|
|
60
|
+
async function getPathsToWatch(context) {
|
|
54
61
|
const plugins = await (0, init_1.initPlugins)(context);
|
|
55
62
|
return plugins.flatMap((plugin) => plugin.getPathsToWatch?.() ?? []);
|
|
56
63
|
}
|
|
57
|
-
//
|
|
64
|
+
// The CLI already validates --syntax, but not the programmatic API
|
|
58
65
|
function validateOptions(options) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
throw new Error(`Invalid --syntax value "${options.syntax}". Valid values: ${validSyntaxValues.join(', ')}`);
|
|
66
|
+
if (options.syntax && !exports.HeadingIdSyntaxes.includes(options.syntax)) {
|
|
67
|
+
throw new Error(`Invalid --syntax value "${options.syntax}". Valid values: ${exports.HeadingIdSyntaxes.join(', ')}`);
|
|
62
68
|
}
|
|
63
69
|
if (options.overwrite && options.migrate) {
|
|
64
70
|
throw new Error("Options --overwrite and --migrate cannot be used together.\nThe --overwrite already re-generates IDs in the target syntax, so the --migrate option wouldn't have any effect.");
|
|
@@ -67,13 +73,14 @@ function validateOptions(options) {
|
|
|
67
73
|
async function writeHeadingIds(siteDirParam = '.', files = [], options = {}) {
|
|
68
74
|
validateOptions(options);
|
|
69
75
|
const siteDir = await (0, fs_1.realpath)(siteDirParam);
|
|
70
|
-
const
|
|
76
|
+
const context = await (0, site_1.loadContext)({ siteDir });
|
|
77
|
+
const patterns = files.length ? files : await getPathsToWatch(context);
|
|
71
78
|
const markdownFiles = await globMarkdownFiles(patterns);
|
|
72
79
|
if (markdownFiles.length === 0) {
|
|
73
80
|
logger_1.default.warn `No markdown files found in siteDir path=${siteDir} for patterns: ${patterns}`;
|
|
74
81
|
return;
|
|
75
82
|
}
|
|
76
|
-
const result = await Promise.all(markdownFiles.map((p) => transformMarkdownFile(p, options)));
|
|
83
|
+
const result = await Promise.all(markdownFiles.map((p) => transformMarkdownFile(p, context.siteConfig.markdown, options)));
|
|
77
84
|
const pathsModified = result.filter(Boolean);
|
|
78
85
|
if (pathsModified.length) {
|
|
79
86
|
logger_1.default.success `Heading ids added to Markdown files (number=${`${pathsModified.length}/${markdownFiles.length}`} files): ${pathsModified}`;
|
|
@@ -199,7 +199,9 @@ const VCS_CONFIG_SCHEMA = utils_validation_1.Joi.custom((input) => {
|
|
|
199
199
|
}
|
|
200
200
|
return value;
|
|
201
201
|
}).default(() => exports.DEFAULT_CONFIG.vcs);
|
|
202
|
+
// TODO Docusaurus v5: remove these never types for removed/renamed options
|
|
202
203
|
const FUTURE_CONFIG_SCHEMA = utils_validation_1.Joi.object({
|
|
204
|
+
// TODO Docusaurus v5: remove this migration error
|
|
203
205
|
faster: utils_validation_1.Joi.any()
|
|
204
206
|
.forbidden()
|
|
205
207
|
.messages({
|
|
@@ -208,11 +210,13 @@ const FUTURE_CONFIG_SCHEMA = utils_validation_1.Joi.object({
|
|
|
208
210
|
experimental_router: utils_validation_1.Joi.string()
|
|
209
211
|
.equal('browser', 'hash')
|
|
210
212
|
.default(exports.DEFAULT_FUTURE_CONFIG.experimental_router),
|
|
213
|
+
// TODO Docusaurus v5: remove this migration error
|
|
211
214
|
experimental_storage: utils_validation_1.Joi.any()
|
|
212
215
|
.forbidden()
|
|
213
216
|
.messages({
|
|
214
217
|
'any.unknown': `The Docusaurus config ${logger_1.default.code('future.experimental_storage')} has been promoted to a stable top-level ${logger_1.default.code('storage')} config attribute. Please move your storage config to the top level.`,
|
|
215
218
|
}),
|
|
219
|
+
// TODO Docusaurus v5: remove this migration error
|
|
216
220
|
experimental_faster: utils_validation_1.Joi.any()
|
|
217
221
|
.forbidden()
|
|
218
222
|
.messages({
|
|
@@ -240,6 +244,7 @@ exports.ConfigSchema = utils_validation_1.Joi.object({
|
|
|
240
244
|
onBrokenAnchors: utils_validation_1.Joi.string()
|
|
241
245
|
.equal('ignore', 'log', 'warn', 'throw')
|
|
242
246
|
.default(exports.DEFAULT_CONFIG.onBrokenAnchors),
|
|
247
|
+
// TODO Docusaurus v5: remove this migration error
|
|
243
248
|
onBrokenMarkdownLinks: utils_validation_1.Joi.any()
|
|
244
249
|
.forbidden()
|
|
245
250
|
.messages({
|
|
@@ -274,6 +279,7 @@ exports.ConfigSchema = utils_validation_1.Joi.object({
|
|
|
274
279
|
})
|
|
275
280
|
.default(exports.DEFAULT_CONFIG.scripts),
|
|
276
281
|
ssgTemplate: utils_validation_1.Joi.string(),
|
|
282
|
+
// TODO Docusaurus v5: remove this migration error
|
|
277
283
|
ssrTemplate: utils_validation_1.Joi.any()
|
|
278
284
|
.forbidden()
|
|
279
285
|
.messages({
|
|
@@ -29,6 +29,7 @@ const uselessBabelConfigMessages = async ({ site }) => {
|
|
|
29
29
|
}
|
|
30
30
|
return [];
|
|
31
31
|
};
|
|
32
|
+
// TODO Docusaurus v5: remove this deprecation warning with Webpack support
|
|
32
33
|
const webpackDeprecationMessages = async ({ site }) => {
|
|
33
34
|
if (site.props.siteConfig.webpack) {
|
|
34
35
|
return [
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/core",
|
|
3
3
|
"description": "Easy to Maintain Open Source Documentation Websites",
|
|
4
|
-
"version": "4.0.0-canary-
|
|
4
|
+
"version": "4.0.0-canary-6973",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -27,15 +27,15 @@
|
|
|
27
27
|
"url": "https://github.com/facebook/docusaurus/issues"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@docusaurus/babel": "4.0.0-canary-
|
|
31
|
-
"@docusaurus/bundler": "4.0.0-canary-
|
|
32
|
-
"@docusaurus/fs": "4.0.0-canary-
|
|
33
|
-
"@docusaurus/glob": "4.0.0-canary-
|
|
34
|
-
"@docusaurus/logger": "4.0.0-canary-
|
|
35
|
-
"@docusaurus/mdx-loader": "4.0.0-canary-
|
|
36
|
-
"@docusaurus/utils": "4.0.0-canary-
|
|
37
|
-
"@docusaurus/utils-common": "4.0.0-canary-
|
|
38
|
-
"@docusaurus/utils-validation": "4.0.0-canary-
|
|
30
|
+
"@docusaurus/babel": "4.0.0-canary-6973",
|
|
31
|
+
"@docusaurus/bundler": "4.0.0-canary-6973",
|
|
32
|
+
"@docusaurus/fs": "4.0.0-canary-6973",
|
|
33
|
+
"@docusaurus/glob": "4.0.0-canary-6973",
|
|
34
|
+
"@docusaurus/logger": "4.0.0-canary-6973",
|
|
35
|
+
"@docusaurus/mdx-loader": "4.0.0-canary-6973",
|
|
36
|
+
"@docusaurus/utils": "4.0.0-canary-6973",
|
|
37
|
+
"@docusaurus/utils-common": "4.0.0-canary-6973",
|
|
38
|
+
"@docusaurus/utils-validation": "4.0.0-canary-6973",
|
|
39
39
|
"@rspack/core": "^2.2.3",
|
|
40
40
|
"@rspack/dev-server": "^2.2.1",
|
|
41
41
|
"boxen": "^9.0.0",
|
|
@@ -68,8 +68,8 @@
|
|
|
68
68
|
"webpack-merge": "^6.0.1"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
|
-
"@docusaurus/module-type-aliases": "4.0.0-canary-
|
|
72
|
-
"@docusaurus/types": "4.0.0-canary-
|
|
71
|
+
"@docusaurus/module-type-aliases": "4.0.0-canary-6973",
|
|
72
|
+
"@docusaurus/types": "4.0.0-canary-6973",
|
|
73
73
|
"@total-typescript/shoehorn": "^0.1.2",
|
|
74
74
|
"@types/escape-html": "^1.0.4",
|
|
75
75
|
"@types/history": "^4.7.11",
|