@docusaurus/core 0.0.0-4667 → 0.0.0-4676

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.
@@ -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;
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-4667",
4
+ "version": "0.0.0-4676",
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-4667",
45
- "@docusaurus/logger": "0.0.0-4667",
46
- "@docusaurus/mdx-loader": "0.0.0-4667",
44
+ "@docusaurus/cssnano-preset": "0.0.0-4676",
45
+ "@docusaurus/logger": "0.0.0-4676",
46
+ "@docusaurus/mdx-loader": "0.0.0-4676",
47
47
  "@docusaurus/react-loadable": "5.5.2",
48
- "@docusaurus/utils": "0.0.0-4667",
49
- "@docusaurus/utils-common": "0.0.0-4667",
50
- "@docusaurus/utils-validation": "0.0.0-4667",
48
+ "@docusaurus/utils": "0.0.0-4676",
49
+ "@docusaurus/utils-common": "0.0.0-4676",
50
+ "@docusaurus/utils-validation": "0.0.0-4676",
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-4667",
110
- "@docusaurus/types": "0.0.0-4667",
109
+ "@docusaurus/module-type-aliases": "0.0.0-4676",
110
+ "@docusaurus/types": "0.0.0-4676",
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": "17b861f5e6de860b0c39642337d3f9a1ba12507b"
131
+ "gitHead": "47f19c51bb30b6bb9498cb50fdadb68b7743cccb"
132
132
  }