Skip to content

Commit c84d779

Browse files
slorberstnorJosh-Cenadependabot[bot]Matija Sirk
authored
chore: backport retro compatible commits for the Docusaurus v2.3 release (#8585)
Co-authored-by: stnor <[email protected]> Co-authored-by: Joshua Chen <[email protected]> Co-authored-by: sebastienlorber <[email protected]> Co-authored-by: Sébastien Lorber <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Matija Sirk <[email protected]> Co-authored-by: AHMET BAYHAN BAYRAMOGLU <[email protected]> Co-authored-by: Stefan Norberg <[email protected]> Co-authored-by: Josh Goldberg <[email protected]> Co-authored-by: Muhammad Hammad <[email protected]> Co-authored-by: Denis Al-Khelali <[email protected]> Co-authored-by: Balthasar Hofer <[email protected]> Co-authored-by: Danny Kim <[email protected]> Co-authored-by: Frieder Bluemle <[email protected]> Co-authored-by: John Reilly <[email protected]> Co-authored-by: Robert Lawrence <[email protected]> Co-authored-by: Sadegh Karimi <[email protected]> Co-authored-by: Lachlan Heywood <[email protected]> Co-authored-by: mturoci <[email protected]> Co-authored-by: 宋锦丰 <[email protected]> Co-authored-by: Nguyễn Thành Nam <[email protected]> Co-authored-by: Dongjoon Lee <[email protected]> Co-authored-by: Thomas.CA <[email protected]> Co-authored-by: Riccardo <[email protected]> Co-authored-by: Lane Goolsby <[email protected]> Co-authored-by: Mariusz Krzaczkowski <[email protected]> Co-authored-by: Matija Sirk <[email protected]> Co-authored-by: Jiří <[email protected]>
1 parent de97214 commit c84d779

File tree

173 files changed

+2638
-1197
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

173 files changed

+2638
-1197
lines changed

admin/new.docusaurus.io/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "new.docusaurus.io",
3-
"version": "2.2.0",
3+
"version": "2.3.0",
44
"private": true,
55
"scripts": {
66
"start": "npx --package netlify-cli netlify dev"

lerna.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "2.2.0",
2+
"version": "2.3.0",
33
"npmClient": "yarn",
44
"useWorkspaces": true,
55
"changelog": {

packages/create-docusaurus/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "create-docusaurus",
3-
"version": "2.2.0",
3+
"version": "2.3.0",
44
"description": "Create Docusaurus apps easily.",
55
"type": "module",
66
"repository": {
@@ -22,8 +22,8 @@
2222
},
2323
"license": "MIT",
2424
"dependencies": {
25-
"@docusaurus/logger": "2.2.0",
26-
"@docusaurus/utils": "2.2.0",
25+
"@docusaurus/logger": "2.3.0",
26+
"@docusaurus/utils": "2.3.0",
2727
"commander": "^5.1.0",
2828
"fs-extra": "^10.1.0",
2929
"lodash": "^4.17.21",

packages/create-docusaurus/templates/classic-typescript/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "docusaurus-2-classic-typescript-template",
3-
"version": "2.2.0",
3+
"version": "2.3.0",
44
"private": true,
55
"scripts": {
66
"docusaurus": "docusaurus",
@@ -15,16 +15,16 @@
1515
"typecheck": "tsc"
1616
},
1717
"dependencies": {
18-
"@docusaurus/core": "2.2.0",
19-
"@docusaurus/preset-classic": "2.2.0",
18+
"@docusaurus/core": "2.3.0",
19+
"@docusaurus/preset-classic": "2.3.0",
2020
"@mdx-js/react": "^1.6.22",
2121
"clsx": "^1.2.1",
2222
"prism-react-renderer": "^1.3.5",
2323
"react": "^17.0.2",
2424
"react-dom": "^17.0.2"
2525
},
2626
"devDependencies": {
27-
"@docusaurus/module-type-aliases": "2.2.0",
27+
"@docusaurus/module-type-aliases": "2.3.0",
2828
"@tsconfig/docusaurus": "^1.0.5",
2929
"typescript": "^4.7.4"
3030
},

packages/create-docusaurus/templates/classic/docusaurus.config.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,22 @@ const darkCodeTheme = require('prism-react-renderer/themes/dracula');
88
const config = {
99
title: 'My Site',
1010
tagline: 'Dinosaurs are cool',
11+
favicon: 'img/favicon.ico',
12+
13+
// Set the production url of your site here
1114
url: 'https://your-docusaurus-test-site.com',
15+
// Set the /<baseUrl>/ pathname under which your site is served
16+
// For GitHub pages deployment, it is often '/<projectName>/'
1217
baseUrl: '/',
13-
onBrokenLinks: 'throw',
14-
onBrokenMarkdownLinks: 'warn',
15-
favicon: 'img/favicon.ico',
1618

1719
// GitHub pages deployment config.
1820
// If you aren't using GitHub pages, you don't need these.
1921
organizationName: 'facebook', // Usually your GitHub org/user name.
2022
projectName: 'docusaurus', // Usually your repo name.
2123

24+
onBrokenLinks: 'throw',
25+
onBrokenMarkdownLinks: 'warn',
26+
2227
// Even if you don't use internalization, you can use this field to set useful
2328
// metadata like html lang. For example, if your site is Chinese, you may want
2429
// to replace "en" with "zh-Hans".
@@ -56,6 +61,8 @@ const config = {
5661
themeConfig:
5762
/** @type {import('@docusaurus/preset-classic').ThemeConfig} */
5863
({
64+
// Replace with your project's social card
65+
image: 'img/docusaurus-social-card.jpg',
5966
navbar: {
6067
title: 'My Site',
6168
logo: {

packages/create-docusaurus/templates/classic/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "docusaurus-2-classic-template",
3-
"version": "2.2.0",
3+
"version": "2.3.0",
44
"private": true,
55
"scripts": {
66
"docusaurus": "docusaurus",
@@ -14,16 +14,16 @@
1414
"write-heading-ids": "docusaurus write-heading-ids"
1515
},
1616
"dependencies": {
17-
"@docusaurus/core": "2.2.0",
18-
"@docusaurus/preset-classic": "2.2.0",
17+
"@docusaurus/core": "2.3.0",
18+
"@docusaurus/preset-classic": "2.3.0",
1919
"@mdx-js/react": "^1.6.22",
2020
"clsx": "^1.2.1",
2121
"prism-react-renderer": "^1.3.5",
2222
"react": "^17.0.2",
2323
"react-dom": "^17.0.2"
2424
},
2525
"devDependencies": {
26-
"@docusaurus/module-type-aliases": "2.2.0"
26+
"@docusaurus/module-type-aliases": "2.3.0"
2727
},
2828
"browserslist": {
2929
"production": [

packages/create-docusaurus/templates/facebook/docusaurus.config.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,22 @@
1313
const config = {
1414
title: 'My Site',
1515
tagline: 'The tagline of my site',
16+
favicon: 'img/favicon.ico',
17+
18+
// Set the production url of your site here
1619
url: 'https://your-docusaurus-test-site.com',
20+
// Set the /<baseUrl>/ pathname under which your site is served
21+
// For GitHub pages deployment, it is often '/<projectName>/'
1722
baseUrl: '/',
18-
onBrokenLinks: 'throw',
19-
onBrokenMarkdownLinks: 'warn',
20-
favicon: 'img/favicon.ico',
2123

2224
// GitHub pages deployment config.
2325
// If you aren't using GitHub pages, you don't need these.
2426
organizationName: 'facebook', // Usually your GitHub org/user name.
2527
projectName: 'docusaurus', // Usually your repo name.
2628

29+
onBrokenLinks: 'throw',
30+
onBrokenMarkdownLinks: 'warn',
31+
2732
presets: [
2833
[
2934
'classic',
@@ -53,6 +58,7 @@ const config = {
5358
themeConfig:
5459
/** @type {import('@docusaurus/preset-classic').ThemeConfig} */
5560
({
61+
image: 'img/docusaurus-social-card.jpg',
5662
navbar: {
5763
title: 'My Meta Project',
5864
logo: {

packages/create-docusaurus/templates/facebook/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "docusaurus-2-facebook-template",
3-
"version": "2.2.0",
3+
"version": "2.3.0",
44
"private": true,
55
"scripts": {
66
"docusaurus": "docusaurus",
@@ -18,8 +18,8 @@
1818
"format:diff": "prettier --config .prettierrc --list-different \"**/*.{js,jsx,ts,tsx,md,mdx}\""
1919
},
2020
"dependencies": {
21-
"@docusaurus/core": "2.2.0",
22-
"@docusaurus/preset-classic": "2.2.0",
21+
"@docusaurus/core": "2.3.0",
22+
"@docusaurus/preset-classic": "2.3.0",
2323
"@mdx-js/react": "^1.6.22",
2424
"clsx": "^1.2.1",
2525
"react": "^17.0.2",

packages/create-docusaurus/templates/shared/docs/tutorial-basics/markdown-features.mdx

+5-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ You can use absolute paths to reference images in the static directory (`static/
5151

5252
![Docusaurus logo](/img/docusaurus.png)
5353

54-
You can reference images relative to the current file as well, as shown in [the extra guides](../tutorial-extras/manage-docs-versions.md).
54+
You can reference images relative to the current file as well. This is particularly useful to colocate images close to the Markdown files using them:
55+
56+
```md
57+
![Docusaurus logo](./img/docusaurus.png)
58+
```
5559

5660
## Code Blocks
5761

Loading

packages/docusaurus-cssnano-preset/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@docusaurus/cssnano-preset",
3-
"version": "2.2.0",
3+
"version": "2.3.0",
44
"description": "Advanced cssnano preset for maximum optimization.",
55
"main": "lib/index.js",
66
"license": "MIT",

packages/docusaurus-logger/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@docusaurus/logger",
3-
"version": "2.2.0",
3+
"version": "2.3.0",
44
"description": "An encapsulated logger for semantically formatting console messages.",
55
"main": "./lib/index.js",
66
"repository": {

packages/docusaurus-mdx-loader/package.json

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@docusaurus/mdx-loader",
3-
"version": "2.2.0",
3+
"version": "2.3.0",
44
"description": "Docusaurus Loader for MDX",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",
@@ -20,8 +20,8 @@
2020
"dependencies": {
2121
"@babel/parser": "^7.18.8",
2222
"@babel/traverse": "^7.18.8",
23-
"@docusaurus/logger": "2.2.0",
24-
"@docusaurus/utils": "2.2.0",
23+
"@docusaurus/logger": "2.3.0",
24+
"@docusaurus/utils": "2.3.0",
2525
"@mdx-js/mdx": "^1.6.22",
2626
"escape-html": "^1.0.3",
2727
"file-loader": "^6.2.0",
@@ -37,10 +37,9 @@
3737
"webpack": "^5.73.0"
3838
},
3939
"devDependencies": {
40-
"@docusaurus/types": "2.2.0",
40+
"@docusaurus/types": "2.3.0",
4141
"@types/escape-html": "^1.0.2",
4242
"@types/mdast": "^3.0.10",
43-
"@types/mermaid": "^8.2.9",
4443
"@types/stringify-object": "^3.3.1",
4544
"@types/unist": "^2.0.6",
4645
"rehype-stringify": "^8.0.0",

packages/docusaurus-mdx-loader/src/remark/admonitions/__tests__/__fixtures__/nesting.md

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/docusaurus-mdx-loader/src/remark/admonitions/__tests__/__snapshots__/index.test.ts.snap

+5
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,8 @@ exports[`admonitions remark plugin interpolation 1`] = `
4242
"<p>Test admonition with interpolated title/body</p>
4343
<admonition type="tip"><mdxAdmonitionTitle>My <code>interpolated</code> <strong>title</strong> &#x3C;button style={{color: "red"}} onClick={() => alert("click")}>test</mdxAdmonitionTitle><p><code>body</code> <strong>interpolated</strong> content</p></admonition>"
4444
`;
45+
46+
exports[`admonitions remark plugin nesting 1`] = `
47+
"<p>Test nested Admonitions</p>
48+
<admonition type="info"><mdxAdmonitionTitle><strong>Weather</strong></mdxAdmonitionTitle><p>On nice days, you can enjoy skiing in the mountains.</p><admonition type="danger"><mdxAdmonitionTitle><em>Storms</em></mdxAdmonitionTitle><p>Take care of snowstorms...</p></admonition></admonition>"
49+
`;

packages/docusaurus-mdx-loader/src/remark/admonitions/__tests__/index.test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,9 @@ describe('admonitions remark plugin', () => {
5050
const result = await processFixture('interpolation');
5151
expect(result).toMatchSnapshot();
5252
});
53+
54+
it('nesting', async () => {
55+
const result = await processFixture('nesting');
56+
expect(result).toMatchSnapshot();
57+
});
5358
});

packages/docusaurus-mdx-loader/src/remark/admonitions/index.ts

+42-6
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,20 @@ const plugin: Plugin = function plugin(
5252
const options = normalizeOptions(optionsInput);
5353

5454
const keywords = Object.values(options.keywords).map(escapeRegExp).join('|');
55+
const nestingChar = escapeRegExp(options.tag.slice(0, 1));
5556
const tag = escapeRegExp(options.tag);
56-
const regex = new RegExp(`${tag}(${keywords})(?: *(.*))?\n`);
57-
const escapeTag = new RegExp(escapeRegExp(`\\${options.tag}`), 'g');
57+
58+
// resolve th nesting level of an opening tag
59+
// ::: -> 0, :::: -> 1, ::::: -> 2 ...
60+
const nestingLevelRegex = new RegExp(
61+
`^${tag}(?<nestingLevel>${nestingChar}*)`,
62+
);
63+
64+
const regex = new RegExp(`${tag}${nestingChar}*(${keywords})(?: *(.*))?\n`);
65+
const escapeTag = new RegExp(
66+
escapeRegExp(`\\${options.tag}${options.tag.slice(0, 1)}*`),
67+
'g',
68+
);
5869

5970
// The tokenizer is called on blocks to determine if there is an admonition
6071
// present and create tags for it
@@ -77,6 +88,11 @@ const plugin: Plugin = function plugin(
7788
];
7889
const food = [];
7990
const content = [];
91+
// get the nesting level of the opening tag
92+
const openingLevel =
93+
nestingLevelRegex.exec(opening)!.groups!.nestingLevel!.length;
94+
// used as a stack to keep track of nested admonitions
95+
const nestingLevels: number[] = [openingLevel];
8096

8197
let newValue = value;
8298
// consume lines until a closing tag
@@ -88,12 +104,32 @@ const plugin: Plugin = function plugin(
88104
next !== -1 ? newValue.slice(idx + 1, next) : newValue.slice(idx + 1);
89105
food.push(line);
90106
newValue = newValue.slice(idx + 1);
91-
// the closing tag is NOT part of the content
92-
if (line.startsWith(options.tag)) {
93-
break;
107+
const nesting = nestingLevelRegex.exec(line);
108+
idx = newValue.indexOf(NEWLINE);
109+
if (!nesting) {
110+
content.push(line);
111+
continue;
112+
}
113+
const tagLevel = nesting.groups!.nestingLevel!.length;
114+
// first level
115+
if (nestingLevels.length === 0) {
116+
nestingLevels.push(tagLevel);
117+
content.push(line);
118+
continue;
119+
}
120+
const currentLevel = nestingLevels[nestingLevels.length - 1]!;
121+
if (tagLevel < currentLevel) {
122+
// entering a nested admonition block
123+
nestingLevels.push(tagLevel);
124+
} else if (tagLevel === currentLevel) {
125+
// closing a nested admonition block
126+
nestingLevels.pop();
127+
// the closing tag is NOT part of the content
128+
if (nestingLevels.length === 0) {
129+
break;
130+
}
94131
}
95132
content.push(line);
96-
idx = newValue.indexOf(NEWLINE);
97133
}
98134

99135
// consume the processed tag and replace escape sequences

packages/docusaurus-migrate/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@docusaurus/migrate",
3-
"version": "2.2.0",
3+
"version": "2.3.0",
44
"description": "A CLI tool to migrate from older versions of Docusaurus.",
55
"license": "MIT",
66
"engines": {
@@ -24,8 +24,8 @@
2424
"dependencies": {
2525
"@babel/core": "^7.18.6",
2626
"@babel/preset-env": "^7.18.6",
27-
"@docusaurus/logger": "2.2.0",
28-
"@docusaurus/utils": "2.2.0",
27+
"@docusaurus/logger": "2.3.0",
28+
"@docusaurus/utils": "2.3.0",
2929
"@mapbox/hast-util-to-jsx": "^2.0.0",
3030
"color": "^4.2.3",
3131
"commander": "^5.1.0",

packages/docusaurus-migrate/src/__tests__/__snapshots__/index.test.ts.snap

+3-3
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ exports[`migration CLI migrates complex website: write 1`] = `
120120
]
121121
}
122122
],
123-
"copyright": "Copyright © 2022 Facebook Inc.",
123+
"copyright": "Copyright © 2023 Facebook Inc.",
124124
"logo": {
125125
"src": "img/docusaurus_monochrome.svg"
126126
}
@@ -303,7 +303,7 @@ exports[`migration CLI migrates missing versions: write 1`] = `
303303
]
304304
}
305305
],
306-
"copyright": "Copyright © 2022 Facebook Inc.",
306+
"copyright": "Copyright © 2023 Facebook Inc.",
307307
"logo": {
308308
"src": "img/docusaurus_monochrome.svg"
309309
}
@@ -483,7 +483,7 @@ exports[`migration CLI migrates simple website: write 1`] = `
483483
]
484484
}
485485
],
486-
"copyright": "Copyright © 2022 Facebook Inc.",
486+
"copyright": "Copyright © 2023 Facebook Inc.",
487487
"logo": {
488488
"src": "img/docusaurus_monochrome.svg"
489489
}

0 commit comments

Comments
 (0)