@docusaurus/theme-classic 0.0.0-4184 → 0.0.0-4192
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/deps.d.ts +13 -0
- package/lib/theme/CodeBlock/index.js +13 -137
- package/lib/theme/NavbarItem/DocNavbarItem.js +1 -3
- package/lib/theme-classic.d.ts +805 -0
- package/lib/types.d.ts +0 -806
- package/lib-next/deps.d.ts +13 -0
- package/lib-next/theme/CodeBlock/index.js +12 -145
- package/lib-next/theme/NavbarItem/DocNavbarItem.js +1 -2
- package/lib-next/theme-classic.d.ts +805 -0
- package/lib-next/types.d.ts +0 -806
- package/package.json +12 -14
- package/src/deps.d.ts +13 -0
- package/src/theme/CodeBlock/index.tsx +13 -158
- package/src/theme/DocPage/index.tsx +1 -1
- package/src/theme/DocSidebarItem/index.tsx +1 -1
- package/src/theme/DocTagDocListPage/index.tsx +1 -1
- package/src/theme/DocVersionBanner/index.tsx +1 -1
- package/src/theme/NavbarItem/DocNavbarItem.tsx +2 -3
- package/src/theme/NavbarItem/DocsVersionDropdownNavbarItem.tsx +1 -1
- package/src/theme-classic.d.ts +805 -0
- package/src/types.d.ts +0 -806
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/theme-classic",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-4192",
|
|
4
4
|
"description": "Classic theme for Docusaurus",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
|
-
"types": "src/
|
|
6
|
+
"types": "src/theme-classic.d.ts",
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"access": "public"
|
|
9
9
|
},
|
|
@@ -23,15 +23,14 @@
|
|
|
23
23
|
"update-code-translations": "node -e 'require(\"./update-code-translations.js\").run()'"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@docusaurus/core": "0.0.0-
|
|
27
|
-
"@docusaurus/plugin-content-blog": "0.0.0-
|
|
28
|
-
"@docusaurus/plugin-content-docs": "0.0.0-
|
|
29
|
-
"@docusaurus/plugin-content-pages": "0.0.0-
|
|
30
|
-
"@docusaurus/theme-common": "0.0.0-
|
|
31
|
-
"@docusaurus/types": "0.0.0-
|
|
32
|
-
"@docusaurus/utils": "0.0.0-
|
|
33
|
-
"@docusaurus/utils-
|
|
34
|
-
"@docusaurus/utils-validation": "0.0.0-4184",
|
|
26
|
+
"@docusaurus/core": "0.0.0-4192",
|
|
27
|
+
"@docusaurus/plugin-content-blog": "0.0.0-4192",
|
|
28
|
+
"@docusaurus/plugin-content-docs": "0.0.0-4192",
|
|
29
|
+
"@docusaurus/plugin-content-pages": "0.0.0-4192",
|
|
30
|
+
"@docusaurus/theme-common": "0.0.0-4192",
|
|
31
|
+
"@docusaurus/types": "0.0.0-4192",
|
|
32
|
+
"@docusaurus/utils": "0.0.0-4192",
|
|
33
|
+
"@docusaurus/utils-validation": "0.0.0-4192",
|
|
35
34
|
"@mdx-js/mdx": "^1.6.21",
|
|
36
35
|
"@mdx-js/react": "^1.6.21",
|
|
37
36
|
"chalk": "^4.1.2",
|
|
@@ -41,7 +40,6 @@
|
|
|
41
40
|
"globby": "^11.0.2",
|
|
42
41
|
"infima": "0.2.0-alpha.34",
|
|
43
42
|
"lodash": "^4.17.20",
|
|
44
|
-
"parse-numeric-range": "^1.3.0",
|
|
45
43
|
"postcss": "^8.3.7",
|
|
46
44
|
"prism-react-renderer": "^1.2.1",
|
|
47
45
|
"prismjs": "^1.23.0",
|
|
@@ -50,7 +48,7 @@
|
|
|
50
48
|
"rtlcss": "^3.3.0"
|
|
51
49
|
},
|
|
52
50
|
"devDependencies": {
|
|
53
|
-
"@docusaurus/module-type-aliases": "0.0.0-
|
|
51
|
+
"@docusaurus/module-type-aliases": "0.0.0-4192",
|
|
54
52
|
"@types/mdx-js__react": "^1.5.4",
|
|
55
53
|
"@types/parse-numeric-range": "^0.0.1",
|
|
56
54
|
"@types/rtlcss": "^3.1.1",
|
|
@@ -64,5 +62,5 @@
|
|
|
64
62
|
"engines": {
|
|
65
63
|
"node": ">=14"
|
|
66
64
|
},
|
|
67
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "13aa4296ce18f2d1c6f7994cb832dd729c668fb2"
|
|
68
66
|
}
|
package/src/deps.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
declare module 'prism-react-renderer/prism' {
|
|
9
|
+
import type * as PrismNamespace from 'prismjs';
|
|
10
|
+
|
|
11
|
+
const Prism: typeof PrismNamespace;
|
|
12
|
+
export default Prism;
|
|
13
|
+
}
|
|
@@ -5,100 +5,22 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import React, {useEffect, useState
|
|
8
|
+
import React, {useEffect, useState} from 'react';
|
|
9
9
|
import clsx from 'clsx';
|
|
10
10
|
import Highlight, {defaultProps, Language} from 'prism-react-renderer';
|
|
11
11
|
import copy from 'copy-text-to-clipboard';
|
|
12
|
-
import
|
|
12
|
+
import Translate, {translate} from '@docusaurus/Translate';
|
|
13
|
+
import {
|
|
14
|
+
useThemeConfig,
|
|
15
|
+
parseCodeBlockTitle,
|
|
16
|
+
parseLanguage,
|
|
17
|
+
parseLines,
|
|
18
|
+
} from '@docusaurus/theme-common';
|
|
13
19
|
import usePrismTheme from '@theme/hooks/usePrismTheme';
|
|
14
20
|
import type {Props} from '@theme/CodeBlock';
|
|
15
|
-
import Translate, {translate} from '@docusaurus/Translate';
|
|
16
21
|
|
|
17
22
|
import styles from './styles.module.css';
|
|
18
23
|
|
|
19
|
-
import {useThemeConfig, parseCodeBlockTitle} from '@docusaurus/theme-common';
|
|
20
|
-
|
|
21
|
-
const HighlightLinesRangeRegex = /{([\d,-]+)}/;
|
|
22
|
-
|
|
23
|
-
const HighlightLanguages = ['js', 'jsBlock', 'jsx', 'python', 'html'] as const;
|
|
24
|
-
type HighlightLanguage = typeof HighlightLanguages[number];
|
|
25
|
-
|
|
26
|
-
type HighlightLanguageConfig = {
|
|
27
|
-
start: string;
|
|
28
|
-
end: string;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
// Supported types of highlight comments
|
|
32
|
-
const HighlightComments: Record<HighlightLanguage, HighlightLanguageConfig> = {
|
|
33
|
-
js: {
|
|
34
|
-
start: '\\/\\/',
|
|
35
|
-
end: '',
|
|
36
|
-
},
|
|
37
|
-
jsBlock: {
|
|
38
|
-
start: '\\/\\*',
|
|
39
|
-
end: '\\*\\/',
|
|
40
|
-
},
|
|
41
|
-
jsx: {
|
|
42
|
-
start: '\\{\\s*\\/\\*',
|
|
43
|
-
end: '\\*\\/\\s*\\}',
|
|
44
|
-
},
|
|
45
|
-
python: {
|
|
46
|
-
start: '#',
|
|
47
|
-
end: '',
|
|
48
|
-
},
|
|
49
|
-
html: {
|
|
50
|
-
start: '<!--',
|
|
51
|
-
end: '-->',
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
// Supported highlight directives
|
|
56
|
-
const HighlightDirectives = [
|
|
57
|
-
'highlight-next-line',
|
|
58
|
-
'highlight-start',
|
|
59
|
-
'highlight-end',
|
|
60
|
-
];
|
|
61
|
-
|
|
62
|
-
const getHighlightDirectiveRegex = (
|
|
63
|
-
languages: readonly HighlightLanguage[] = HighlightLanguages,
|
|
64
|
-
) => {
|
|
65
|
-
// to be more reliable, the opening and closing comment must match
|
|
66
|
-
const commentPattern = languages
|
|
67
|
-
.map((lang) => {
|
|
68
|
-
const {start, end} = HighlightComments[lang];
|
|
69
|
-
return `(?:${start}\\s*(${HighlightDirectives.join('|')})\\s*${end})`;
|
|
70
|
-
})
|
|
71
|
-
.join('|');
|
|
72
|
-
// white space is allowed, but otherwise it should be on it's own line
|
|
73
|
-
return new RegExp(`^\\s*(?:${commentPattern})\\s*$`);
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
// select comment styles based on language
|
|
77
|
-
const highlightDirectiveRegex = (lang: string) => {
|
|
78
|
-
switch (lang) {
|
|
79
|
-
case 'js':
|
|
80
|
-
case 'javascript':
|
|
81
|
-
case 'ts':
|
|
82
|
-
case 'typescript':
|
|
83
|
-
return getHighlightDirectiveRegex(['js', 'jsBlock']);
|
|
84
|
-
|
|
85
|
-
case 'jsx':
|
|
86
|
-
case 'tsx':
|
|
87
|
-
return getHighlightDirectiveRegex(['js', 'jsBlock', 'jsx']);
|
|
88
|
-
|
|
89
|
-
case 'html':
|
|
90
|
-
return getHighlightDirectiveRegex(['js', 'jsBlock', 'html']);
|
|
91
|
-
|
|
92
|
-
case 'python':
|
|
93
|
-
case 'py':
|
|
94
|
-
return getHighlightDirectiveRegex(['python']);
|
|
95
|
-
|
|
96
|
-
default:
|
|
97
|
-
// all comment types
|
|
98
|
-
return getHighlightDirectiveRegex();
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
|
|
102
24
|
export default function CodeBlock({
|
|
103
25
|
children,
|
|
104
26
|
className: blockClassName,
|
|
@@ -124,10 +46,6 @@ export default function CodeBlock({
|
|
|
124
46
|
// so we probably don't need to parse the metastring
|
|
125
47
|
// (note: title="xyz" => title prop still has the quotes)
|
|
126
48
|
const codeBlockTitle = parseCodeBlockTitle(metastring) || title;
|
|
127
|
-
|
|
128
|
-
const button = useRef(null);
|
|
129
|
-
let highlightLines: number[] = [];
|
|
130
|
-
|
|
131
49
|
const prismTheme = usePrismTheme();
|
|
132
50
|
|
|
133
51
|
// In case interleaved Markdown (e.g. when using CodeBlock as standalone component).
|
|
@@ -135,67 +53,9 @@ export default function CodeBlock({
|
|
|
135
53
|
? children.join('')
|
|
136
54
|
: (children as string);
|
|
137
55
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
highlightLines = rangeParser(highlightLinesRange).filter((n) => n > 0);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
const languageClassName = blockClassName
|
|
145
|
-
?.split(' ')
|
|
146
|
-
.find((str) => str.startsWith('language-'));
|
|
147
|
-
let language = languageClassName?.replace(/language-/, '') as Language;
|
|
148
|
-
|
|
149
|
-
if (!language && prism.defaultLanguage) {
|
|
150
|
-
language = prism.defaultLanguage as Language;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// only declaration OR directive highlight can be used for a block
|
|
154
|
-
let code = content.replace(/\n$/, '');
|
|
155
|
-
if (highlightLines.length === 0 && language !== undefined) {
|
|
156
|
-
let range = '';
|
|
157
|
-
const directiveRegex = highlightDirectiveRegex(language);
|
|
158
|
-
// go through line by line
|
|
159
|
-
const lines = content.replace(/\n$/, '').split('\n');
|
|
160
|
-
let blockStart: number;
|
|
161
|
-
// loop through lines
|
|
162
|
-
for (let index = 0; index < lines.length; ) {
|
|
163
|
-
const line = lines[index];
|
|
164
|
-
// adjust for 0-index
|
|
165
|
-
const lineNumber = index + 1;
|
|
166
|
-
const match = line.match(directiveRegex);
|
|
167
|
-
if (match !== null) {
|
|
168
|
-
const directive = match
|
|
169
|
-
.slice(1)
|
|
170
|
-
.reduce(
|
|
171
|
-
(final: string | undefined, item) => final || item,
|
|
172
|
-
undefined,
|
|
173
|
-
);
|
|
174
|
-
switch (directive) {
|
|
175
|
-
case 'highlight-next-line':
|
|
176
|
-
range += `${lineNumber},`;
|
|
177
|
-
break;
|
|
178
|
-
|
|
179
|
-
case 'highlight-start':
|
|
180
|
-
blockStart = lineNumber;
|
|
181
|
-
break;
|
|
182
|
-
|
|
183
|
-
case 'highlight-end':
|
|
184
|
-
range += `${blockStart!}-${lineNumber - 1},`;
|
|
185
|
-
break;
|
|
186
|
-
|
|
187
|
-
default:
|
|
188
|
-
break;
|
|
189
|
-
}
|
|
190
|
-
lines.splice(index, 1);
|
|
191
|
-
} else {
|
|
192
|
-
// lines without directives are unchanged
|
|
193
|
-
index += 1;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
highlightLines = rangeParser(range);
|
|
197
|
-
code = lines.join('\n');
|
|
198
|
-
}
|
|
56
|
+
const language =
|
|
57
|
+
parseLanguage(blockClassName) ?? (prism.defaultLanguage as Language);
|
|
58
|
+
const {highlightLines, code} = parseLines(content, metastring, language);
|
|
199
59
|
|
|
200
60
|
const handleCopyCode = () => {
|
|
201
61
|
copy(code);
|
|
@@ -212,11 +72,7 @@ export default function CodeBlock({
|
|
|
212
72
|
code={code}
|
|
213
73
|
language={language}>
|
|
214
74
|
{({className, style, tokens, getLineProps, getTokenProps}) => (
|
|
215
|
-
<div
|
|
216
|
-
className={clsx(
|
|
217
|
-
styles.codeBlockContainer,
|
|
218
|
-
blockClassName?.replace(/language-[^ ]+/, ''),
|
|
219
|
-
)}>
|
|
75
|
+
<div className={clsx(styles.codeBlockContainer, blockClassName)}>
|
|
220
76
|
{codeBlockTitle && (
|
|
221
77
|
<div style={style} className={styles.codeBlockTitle}>
|
|
222
78
|
{codeBlockTitle}
|
|
@@ -236,7 +92,7 @@ export default function CodeBlock({
|
|
|
236
92
|
|
|
237
93
|
const lineProps = getLineProps({line, key: i});
|
|
238
94
|
|
|
239
|
-
if (highlightLines.includes(i
|
|
95
|
+
if (highlightLines.includes(i)) {
|
|
240
96
|
lineProps.className += ' docusaurus-highlight-code-line';
|
|
241
97
|
}
|
|
242
98
|
|
|
@@ -253,7 +109,6 @@ export default function CodeBlock({
|
|
|
253
109
|
</pre>
|
|
254
110
|
|
|
255
111
|
<button
|
|
256
|
-
ref={button}
|
|
257
112
|
type="button"
|
|
258
113
|
aria-label={translate({
|
|
259
114
|
id: 'theme.CodeBlock.copyButtonAriaLabel',
|
|
@@ -9,7 +9,7 @@ import React, {ReactNode, useState, useCallback} from 'react';
|
|
|
9
9
|
import {MDXProvider} from '@mdx-js/react';
|
|
10
10
|
|
|
11
11
|
import renderRoutes from '@docusaurus/renderRoutes';
|
|
12
|
-
import type {PropVersionMetadata} from '@docusaurus/plugin-content-docs
|
|
12
|
+
import type {PropVersionMetadata} from '@docusaurus/plugin-content-docs';
|
|
13
13
|
import Layout from '@theme/Layout';
|
|
14
14
|
import DocSidebar from '@theme/DocSidebar';
|
|
15
15
|
import MDXComponents from '@theme/MDXComponents';
|
|
@@ -22,7 +22,7 @@ import type {Props, DocSidebarItemsProps} from '@theme/DocSidebarItem';
|
|
|
22
22
|
import type {
|
|
23
23
|
PropSidebarItemCategory,
|
|
24
24
|
PropSidebarItemLink,
|
|
25
|
-
} from '@docusaurus/plugin-content-docs
|
|
25
|
+
} from '@docusaurus/plugin-content-docs';
|
|
26
26
|
|
|
27
27
|
import styles from './styles.module.css';
|
|
28
28
|
|
|
@@ -10,7 +10,7 @@ import React from 'react';
|
|
|
10
10
|
import Layout from '@theme/Layout';
|
|
11
11
|
import Link from '@docusaurus/Link';
|
|
12
12
|
import {ThemeClassNames, usePluralForm} from '@docusaurus/theme-common';
|
|
13
|
-
import type {PropTagDocListDoc} from '@docusaurus/plugin-content-docs
|
|
13
|
+
import type {PropTagDocListDoc} from '@docusaurus/plugin-content-docs';
|
|
14
14
|
import Translate, {translate} from '@docusaurus/Translate';
|
|
15
15
|
import type {Props} from '@theme/DocTagDocListPage';
|
|
16
16
|
|
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
|
|
22
22
|
import type {Props} from '@theme/DocVersionBanner';
|
|
23
23
|
import clsx from 'clsx';
|
|
24
|
-
import type {VersionBanner} from '@docusaurus/plugin-content-docs
|
|
24
|
+
import type {VersionBanner} from '@docusaurus/plugin-content-docs';
|
|
25
25
|
|
|
26
26
|
type BannerLabelComponentProps = {
|
|
27
27
|
siteTitle: string;
|
|
@@ -11,9 +11,8 @@ import {useLatestVersion, useActiveDocContext} from '@theme/hooks/useDocs';
|
|
|
11
11
|
import clsx from 'clsx';
|
|
12
12
|
import {getInfimaActiveClassName} from './index';
|
|
13
13
|
import type {Props} from '@theme/NavbarItem/DocNavbarItem';
|
|
14
|
-
import {useDocsPreferredVersion} from '@docusaurus/theme-common';
|
|
15
|
-
import {
|
|
16
|
-
import type {GlobalDataVersion} from '@docusaurus/plugin-content-docs-types';
|
|
14
|
+
import {useDocsPreferredVersion, uniq} from '@docusaurus/theme-common';
|
|
15
|
+
import type {GlobalDataVersion} from '@docusaurus/plugin-content-docs';
|
|
17
16
|
|
|
18
17
|
function getDocInVersions(versions: GlobalDataVersion[], docId: string) {
|
|
19
18
|
const allDocs = versions.flatMap((version) => version.docs);
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
import type {Props} from '@theme/NavbarItem/DocsVersionDropdownNavbarItem';
|
|
17
17
|
import {useDocsPreferredVersion} from '@docusaurus/theme-common';
|
|
18
18
|
import {translate} from '@docusaurus/Translate';
|
|
19
|
-
import type {GlobalDataVersion} from '@docusaurus/plugin-content-docs
|
|
19
|
+
import type {GlobalDataVersion} from '@docusaurus/plugin-content-docs';
|
|
20
20
|
|
|
21
21
|
const getVersionMainDoc = (version: GlobalDataVersion) =>
|
|
22
22
|
version.docs.find((doc) => doc.id === version.mainDocId)!;
|