@docusaurus/core 0.0.0-4671 → 0.0.0-4677

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.
@@ -123,7 +123,7 @@ async function buildLocale({ siteDir, locale, cliOptions, forceTerminate, isLast
123
123
  plugins.forEach((plugin) => {
124
124
  const { configureWebpack, configurePostCss } = plugin;
125
125
  if (configurePostCss) {
126
- clientConfig = (0, utils_1.applyConfigurePostCss)(configurePostCss, clientConfig);
126
+ clientConfig = (0, utils_1.applyConfigurePostCss)(configurePostCss.bind(plugin), clientConfig);
127
127
  }
128
128
  if (configureWebpack) {
129
129
  clientConfig = (0, utils_1.applyConfigureWebpack)(configureWebpack.bind(plugin), // The plugin lifecycle may reference `this`.
@@ -15,11 +15,7 @@ async function externalCommand(cli, siteDir) {
15
15
  const plugins = await (0, init_1.default)({ pluginConfigs, context });
16
16
  // Plugin Lifecycle - extendCli.
17
17
  plugins.forEach((plugin) => {
18
- const { extendCli } = plugin;
19
- if (!extendCli) {
20
- return;
21
- }
22
- extendCli(cli);
18
+ plugin.extendCli?.(cli);
23
19
  });
24
20
  }
25
21
  exports.default = externalCommand;
@@ -116,10 +116,10 @@ async function start(siteDir, cliOptions) {
116
116
  plugins.forEach((plugin) => {
117
117
  const { configureWebpack, configurePostCss } = plugin;
118
118
  if (configurePostCss) {
119
- config = (0, utils_2.applyConfigurePostCss)(configurePostCss, config);
119
+ config = (0, utils_2.applyConfigurePostCss)(configurePostCss.bind(plugin), config);
120
120
  }
121
121
  if (configureWebpack) {
122
- config = (0, utils_2.applyConfigureWebpack)(configureWebpack.bind(plugin), // The plugin lifecycle may reference `this`. // TODO remove this implicit api: inject in callback instead
122
+ config = (0, utils_2.applyConfigureWebpack)(configureWebpack.bind(plugin), // The plugin lifecycle may reference `this`.
123
123
  config, false, props.siteConfig.webpack?.jsLoader, plugin.content);
124
124
  }
125
125
  });
@@ -4,12 +4,10 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import { type Slugger } from '@docusaurus/utils';
8
7
  declare type Options = {
9
8
  maintainCase?: boolean;
10
9
  overwrite?: boolean;
11
10
  };
12
- export declare function transformMarkdownHeadingLine(line: string, slugger: Slugger, options?: Options): string;
13
11
  export declare function transformMarkdownContent(content: string, options?: Options): string;
14
12
  export default function writeHeadingIds(siteDir: string, files?: string[], options?: Options): Promise<void>;
15
13
  export {};
@@ -6,7 +6,7 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.transformMarkdownContent = exports.transformMarkdownHeadingLine = void 0;
9
+ exports.transformMarkdownContent = void 0;
10
10
  const tslib_1 = require("tslib");
11
11
  const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
12
12
  const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
@@ -24,53 +24,49 @@ function addHeadingId(line, slugger, maintainCase) {
24
24
  }
25
25
  const headingText = line.slice(headingLevel).trimEnd();
26
26
  const headingHashes = line.slice(0, headingLevel);
27
- const slug = slugger
28
- .slug(unwrapMarkdownLinks(headingText).trim(), { maintainCase })
29
- .replace(/^-+/, '')
30
- .replace(/-+$/, '');
27
+ const slug = slugger.slug(unwrapMarkdownLinks(headingText).trim(), {
28
+ maintainCase,
29
+ });
31
30
  return `${headingHashes}${headingText} {#${slug}}`;
32
31
  }
33
- function transformMarkdownHeadingLine(line, slugger, options = { maintainCase: false, overwrite: false }) {
32
+ function transformMarkdownContent(content, options = { maintainCase: false, overwrite: false }) {
34
33
  const { maintainCase = false, overwrite = false } = options;
35
- if (!line.startsWith('#')) {
36
- throw new Error(`Line is not a Markdown heading: ${line}.`);
37
- }
38
- const parsedHeading = (0, utils_1.parseMarkdownHeadingId)(line);
39
- // Do not process if id is already there
40
- if (parsedHeading.id && !overwrite) {
41
- return line;
42
- }
43
- return addHeadingId(parsedHeading.text, slugger, maintainCase);
44
- }
45
- exports.transformMarkdownHeadingLine = transformMarkdownHeadingLine;
46
- function transformMarkdownLine(line, slugger, options) {
47
- // Ignore h1 headings on purpose, as we don't create anchor links for those
48
- if (line.startsWith('##')) {
49
- return transformMarkdownHeadingLine(line, slugger, options);
34
+ const lines = content.split('\n');
35
+ const slugger = (0, utils_1.createSlugger)();
36
+ // If we can't overwrite existing slugs, make sure other headings don't
37
+ // generate colliding slugs by first marking these slugs as occupied
38
+ if (!overwrite) {
39
+ lines.forEach((line) => {
40
+ const parsedHeading = (0, utils_1.parseMarkdownHeadingId)(line);
41
+ if (parsedHeading.id) {
42
+ slugger.slug(parsedHeading.id);
43
+ }
44
+ });
50
45
  }
51
- return line;
52
- }
53
- function transformMarkdownLines(lines, options) {
54
46
  let inCode = false;
55
- const slugger = (0, utils_1.createSlugger)();
56
- return lines.map((line) => {
47
+ return lines
48
+ .map((line) => {
57
49
  if (line.startsWith('```')) {
58
50
  inCode = !inCode;
59
51
  return line;
60
52
  }
61
- if (inCode) {
53
+ // Ignore h1 headings, as we don't create anchor links for those
54
+ if (inCode || !line.startsWith('##')) {
62
55
  return line;
63
56
  }
64
- return transformMarkdownLine(line, slugger, options);
65
- });
66
- }
67
- function transformMarkdownContent(content, options) {
68
- return transformMarkdownLines(content.split('\n'), options).join('\n');
57
+ const parsedHeading = (0, utils_1.parseMarkdownHeadingId)(line);
58
+ // Do not process if id is already there
59
+ if (parsedHeading.id && !overwrite) {
60
+ return line;
61
+ }
62
+ return addHeadingId(parsedHeading.text, slugger, maintainCase);
63
+ })
64
+ .join('\n');
69
65
  }
70
66
  exports.transformMarkdownContent = transformMarkdownContent;
71
67
  async function transformMarkdownFile(filepath, options) {
72
68
  const content = await fs_extra_1.default.readFile(filepath, 'utf8');
73
- const updatedContent = transformMarkdownLines(content.split('\n'), options).join('\n');
69
+ const updatedContent = transformMarkdownContent(content, options);
74
70
  if (content !== updatedContent) {
75
71
  await fs_extra_1.default.writeFile(filepath, updatedContent);
76
72
  return filepath;
@@ -39,7 +39,7 @@ async function loadThemeAliases(themePaths, userThemePaths) {
39
39
  exports.loadThemeAliases = loadThemeAliases;
40
40
  function loadPluginsThemeAliases({ siteDir, plugins, }) {
41
41
  const pluginThemes = plugins
42
- .map((plugin) => (plugin.getThemePath ? plugin.getThemePath() : undefined))
42
+ .map((plugin) => plugin.getThemePath?.())
43
43
  .filter((x) => Boolean(x));
44
44
  const userTheme = path_1.default.resolve(siteDir, utils_1.THEME_PATH);
45
45
  return loadThemeAliases([ThemeFallbackDir, ...pluginThemes], [userTheme]);
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": "0.0.0-4671",
4
+ "version": "0.0.0-4677",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -41,13 +41,13 @@
41
41
  "@babel/runtime": "^7.17.2",
42
42
  "@babel/runtime-corejs3": "^7.17.2",
43
43
  "@babel/traverse": "^7.17.3",
44
- "@docusaurus/cssnano-preset": "0.0.0-4671",
45
- "@docusaurus/logger": "0.0.0-4671",
46
- "@docusaurus/mdx-loader": "0.0.0-4671",
44
+ "@docusaurus/cssnano-preset": "0.0.0-4677",
45
+ "@docusaurus/logger": "0.0.0-4677",
46
+ "@docusaurus/mdx-loader": "0.0.0-4677",
47
47
  "@docusaurus/react-loadable": "5.5.2",
48
- "@docusaurus/utils": "0.0.0-4671",
49
- "@docusaurus/utils-common": "0.0.0-4671",
50
- "@docusaurus/utils-validation": "0.0.0-4671",
48
+ "@docusaurus/utils": "0.0.0-4677",
49
+ "@docusaurus/utils-common": "0.0.0-4677",
50
+ "@docusaurus/utils-validation": "0.0.0-4677",
51
51
  "@slorber/static-site-generator-webpack-plugin": "^4.0.1",
52
52
  "@svgr/webpack": "^6.2.1",
53
53
  "autoprefixer": "^10.4.2",
@@ -106,8 +106,8 @@
106
106
  "webpackbar": "^5.0.2"
107
107
  },
108
108
  "devDependencies": {
109
- "@docusaurus/module-type-aliases": "0.0.0-4671",
110
- "@docusaurus/types": "0.0.0-4671",
109
+ "@docusaurus/module-type-aliases": "0.0.0-4677",
110
+ "@docusaurus/types": "0.0.0-4677",
111
111
  "@types/detect-port": "^1.3.2",
112
112
  "@types/nprogress": "^0.2.0",
113
113
  "@types/react-dom": "^17.0.11",
@@ -128,5 +128,5 @@
128
128
  "engines": {
129
129
  "node": ">=14"
130
130
  },
131
- "gitHead": "8789a77f87f8a7132a2915559b57198b78f159c6"
131
+ "gitHead": "e4f370386120aba552fb9783ac8bcea85bf7fe53"
132
132
  }