@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/lib/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
|
+
}
|
|
@@ -13,16 +13,14 @@ var _prismReactRenderer = _interopRequireWildcard(require("prism-react-renderer"
|
|
|
13
13
|
|
|
14
14
|
var _copyTextToClipboard = _interopRequireDefault(require("copy-text-to-clipboard"));
|
|
15
15
|
|
|
16
|
-
var
|
|
16
|
+
var _Translate = _interopRequireWildcard(require("@docusaurus/Translate"));
|
|
17
17
|
|
|
18
|
-
var
|
|
18
|
+
var _themeCommon = require("@docusaurus/theme-common");
|
|
19
19
|
|
|
20
|
-
var
|
|
20
|
+
var _usePrismTheme = _interopRequireDefault(require("@theme/hooks/usePrismTheme"));
|
|
21
21
|
|
|
22
22
|
var _stylesModule = _interopRequireDefault(require("./styles.module.css"));
|
|
23
23
|
|
|
24
|
-
var _themeCommon = require("@docusaurus/theme-common");
|
|
25
|
-
|
|
26
24
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
27
25
|
|
|
28
26
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
@@ -35,79 +33,14 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
35
33
|
* This source code is licensed under the MIT license found in the
|
|
36
34
|
* LICENSE file in the root directory of this source tree.
|
|
37
35
|
*/
|
|
38
|
-
const HighlightLinesRangeRegex = /{([\d,-]+)}/;
|
|
39
|
-
const HighlightLanguages = ['js', 'jsBlock', 'jsx', 'python', 'html'];
|
|
40
|
-
// Supported types of highlight comments
|
|
41
|
-
const HighlightComments = {
|
|
42
|
-
js: {
|
|
43
|
-
start: '\\/\\/',
|
|
44
|
-
end: ''
|
|
45
|
-
},
|
|
46
|
-
jsBlock: {
|
|
47
|
-
start: '\\/\\*',
|
|
48
|
-
end: '\\*\\/'
|
|
49
|
-
},
|
|
50
|
-
jsx: {
|
|
51
|
-
start: '\\{\\s*\\/\\*',
|
|
52
|
-
end: '\\*\\/\\s*\\}'
|
|
53
|
-
},
|
|
54
|
-
python: {
|
|
55
|
-
start: '#',
|
|
56
|
-
end: ''
|
|
57
|
-
},
|
|
58
|
-
html: {
|
|
59
|
-
start: '<!--',
|
|
60
|
-
end: '-->'
|
|
61
|
-
}
|
|
62
|
-
}; // Supported highlight directives
|
|
63
|
-
|
|
64
|
-
const HighlightDirectives = ['highlight-next-line', 'highlight-start', 'highlight-end'];
|
|
65
|
-
|
|
66
|
-
const getHighlightDirectiveRegex = (languages = HighlightLanguages) => {
|
|
67
|
-
// to be more reliable, the opening and closing comment must match
|
|
68
|
-
const commentPattern = languages.map(lang => {
|
|
69
|
-
const {
|
|
70
|
-
start,
|
|
71
|
-
end
|
|
72
|
-
} = HighlightComments[lang];
|
|
73
|
-
return `(?:${start}\\s*(${HighlightDirectives.join('|')})\\s*${end})`;
|
|
74
|
-
}).join('|'); // white space is allowed, but otherwise it should be on it's own line
|
|
75
|
-
|
|
76
|
-
return new RegExp(`^\\s*(?:${commentPattern})\\s*$`);
|
|
77
|
-
}; // select comment styles based on language
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const highlightDirectiveRegex = lang => {
|
|
81
|
-
switch (lang) {
|
|
82
|
-
case 'js':
|
|
83
|
-
case 'javascript':
|
|
84
|
-
case 'ts':
|
|
85
|
-
case 'typescript':
|
|
86
|
-
return getHighlightDirectiveRegex(['js', 'jsBlock']);
|
|
87
|
-
|
|
88
|
-
case 'jsx':
|
|
89
|
-
case 'tsx':
|
|
90
|
-
return getHighlightDirectiveRegex(['js', 'jsBlock', 'jsx']);
|
|
91
|
-
|
|
92
|
-
case 'html':
|
|
93
|
-
return getHighlightDirectiveRegex(['js', 'jsBlock', 'html']);
|
|
94
|
-
|
|
95
|
-
case 'python':
|
|
96
|
-
case 'py':
|
|
97
|
-
return getHighlightDirectiveRegex(['python']);
|
|
98
|
-
|
|
99
|
-
default:
|
|
100
|
-
// all comment types
|
|
101
|
-
return getHighlightDirectiveRegex();
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
|
|
105
36
|
function CodeBlock({
|
|
106
37
|
children,
|
|
107
38
|
className: blockClassName,
|
|
108
39
|
metastring,
|
|
109
40
|
title
|
|
110
41
|
}) {
|
|
42
|
+
var _parseLanguage;
|
|
43
|
+
|
|
111
44
|
const {
|
|
112
45
|
prism
|
|
113
46
|
} = (0, _themeCommon.useThemeConfig)();
|
|
@@ -127,71 +60,14 @@ function CodeBlock({
|
|
|
127
60
|
// (note: title="xyz" => title prop still has the quotes)
|
|
128
61
|
|
|
129
62
|
const codeBlockTitle = (0, _themeCommon.parseCodeBlockTitle)(metastring) || title;
|
|
130
|
-
const button = (0, _react.useRef)(null);
|
|
131
|
-
let highlightLines = [];
|
|
132
63
|
const prismTheme = (0, _usePrismTheme.default)(); // In case interleaved Markdown (e.g. when using CodeBlock as standalone component).
|
|
133
64
|
|
|
134
65
|
const content = Array.isArray(children) ? children.join('') : children;
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
const languageClassName = blockClassName === null || blockClassName === void 0 ? void 0 : blockClassName.split(' ').find(str => str.startsWith('language-'));
|
|
143
|
-
let language = languageClassName === null || languageClassName === void 0 ? void 0 : languageClassName.replace(/language-/, '');
|
|
144
|
-
|
|
145
|
-
if (!language && prism.defaultLanguage) {
|
|
146
|
-
language = prism.defaultLanguage;
|
|
147
|
-
} // only declaration OR directive highlight can be used for a block
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
let code = content.replace(/\n$/, '');
|
|
151
|
-
|
|
152
|
-
if (highlightLines.length === 0 && language !== undefined) {
|
|
153
|
-
let range = '';
|
|
154
|
-
const directiveRegex = highlightDirectiveRegex(language); // go through line by line
|
|
155
|
-
|
|
156
|
-
const lines = content.replace(/\n$/, '').split('\n');
|
|
157
|
-
let blockStart; // loop through lines
|
|
158
|
-
|
|
159
|
-
for (let index = 0; index < lines.length;) {
|
|
160
|
-
const line = lines[index]; // adjust for 0-index
|
|
161
|
-
|
|
162
|
-
const lineNumber = index + 1;
|
|
163
|
-
const match = line.match(directiveRegex);
|
|
164
|
-
|
|
165
|
-
if (match !== null) {
|
|
166
|
-
const directive = match.slice(1).reduce((final, item) => final || item, undefined);
|
|
167
|
-
|
|
168
|
-
switch (directive) {
|
|
169
|
-
case 'highlight-next-line':
|
|
170
|
-
range += `${lineNumber},`;
|
|
171
|
-
break;
|
|
172
|
-
|
|
173
|
-
case 'highlight-start':
|
|
174
|
-
blockStart = lineNumber;
|
|
175
|
-
break;
|
|
176
|
-
|
|
177
|
-
case 'highlight-end':
|
|
178
|
-
range += `${blockStart}-${lineNumber - 1},`;
|
|
179
|
-
break;
|
|
180
|
-
|
|
181
|
-
default:
|
|
182
|
-
break;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
lines.splice(index, 1);
|
|
186
|
-
} else {
|
|
187
|
-
// lines without directives are unchanged
|
|
188
|
-
index += 1;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
highlightLines = (0, _parseNumericRange.default)(range);
|
|
193
|
-
code = lines.join('\n');
|
|
194
|
-
}
|
|
66
|
+
const language = (_parseLanguage = (0, _themeCommon.parseLanguage)(blockClassName)) !== null && _parseLanguage !== void 0 ? _parseLanguage : prism.defaultLanguage;
|
|
67
|
+
const {
|
|
68
|
+
highlightLines,
|
|
69
|
+
code
|
|
70
|
+
} = (0, _themeCommon.parseLines)(content, metastring, language);
|
|
195
71
|
|
|
196
72
|
const handleCopyCode = () => {
|
|
197
73
|
(0, _copyTextToClipboard.default)(code);
|
|
@@ -206,7 +82,7 @@ function CodeBlock({
|
|
|
206
82
|
tokens,
|
|
207
83
|
getLineProps,
|
|
208
84
|
getTokenProps
|
|
209
|
-
}) => <div className={(0, _clsx.default)(_stylesModule.default.codeBlockContainer, blockClassName
|
|
85
|
+
}) => <div className={(0, _clsx.default)(_stylesModule.default.codeBlockContainer, blockClassName)}>
|
|
210
86
|
{codeBlockTitle && <div style={style} className={_stylesModule.default.codeBlockTitle}>
|
|
211
87
|
{codeBlockTitle}
|
|
212
88
|
</div>}
|
|
@@ -225,7 +101,7 @@ function CodeBlock({
|
|
|
225
101
|
key: i
|
|
226
102
|
});
|
|
227
103
|
|
|
228
|
-
if (highlightLines.includes(i
|
|
104
|
+
if (highlightLines.includes(i)) {
|
|
229
105
|
lineProps.className += ' docusaurus-highlight-code-line';
|
|
230
106
|
}
|
|
231
107
|
|
|
@@ -240,7 +116,7 @@ function CodeBlock({
|
|
|
240
116
|
</code>
|
|
241
117
|
</pre>
|
|
242
118
|
|
|
243
|
-
<button
|
|
119
|
+
<button type="button" aria-label={(0, _Translate.translate)({
|
|
244
120
|
id: 'theme.CodeBlock.copyButtonAriaLabel',
|
|
245
121
|
message: 'Copy code to clipboard',
|
|
246
122
|
description: 'The ARIA label for copy code blocks button'
|
|
@@ -17,8 +17,6 @@ var _index = require("./index");
|
|
|
17
17
|
|
|
18
18
|
var _themeCommon = require("@docusaurus/theme-common");
|
|
19
19
|
|
|
20
|
-
var _utilsCommon = require("@docusaurus/utils-common");
|
|
21
|
-
|
|
22
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
21
|
|
|
24
22
|
/**
|
|
@@ -55,7 +53,7 @@ function DocNavbarItem({
|
|
|
55
53
|
} = (0, _themeCommon.useDocsPreferredVersion)(docsPluginId);
|
|
56
54
|
const latestVersion = (0, _useDocs.useLatestVersion)(docsPluginId); // Versions used to look for the doc to link to, ordered + no duplicate
|
|
57
55
|
|
|
58
|
-
const versions = (0,
|
|
56
|
+
const versions = (0, _themeCommon.uniq)([activeVersion, preferredVersion, latestVersion].filter(Boolean));
|
|
59
57
|
const doc = getDocInVersions(versions, docId);
|
|
60
58
|
const activeDocInfimaClassName = (0, _index.getInfimaActiveClassName)(props.mobile);
|
|
61
59
|
return <_DefaultNavbarItem.default exact {...props} className={(0, _clsx.default)(props.className, {
|