@docusaurus/theme-classic 0.0.0-4325 → 0.0.0-4330
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-next/theme/CodeBlock/index.js +32 -3
- package/lib-next/theme/CodeBlock/styles.module.css +5 -0
- package/lib-next/theme/MDXComponents/index.js +12 -25
- package/package.json +12 -12
- package/src/theme/CodeBlock/index.tsx +35 -4
- package/src/theme/CodeBlock/styles.module.css +5 -0
- package/src/theme/MDXComponents/index.tsx +15 -30
|
@@ -4,7 +4,7 @@
|
|
|
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 React, {useEffect, useState} from 'react';
|
|
7
|
+
import React, {isValidElement, useEffect, useState} from 'react';
|
|
8
8
|
import clsx from 'clsx';
|
|
9
9
|
import Highlight, {defaultProps} from 'prism-react-renderer';
|
|
10
10
|
import copy from 'copy-text-to-clipboard';
|
|
@@ -41,7 +41,36 @@ export default function CodeBlock({
|
|
|
41
41
|
// (note: title="xyz" => title prop still has the quotes)
|
|
42
42
|
|
|
43
43
|
const codeBlockTitle = parseCodeBlockTitle(metastring) || title;
|
|
44
|
-
const prismTheme = usePrismTheme(); //
|
|
44
|
+
const prismTheme = usePrismTheme(); // <pre> tags in markdown map to CodeBlocks and they may contain JSX children.
|
|
45
|
+
// When the children is not a simple string, we just return a styled block without actually highlighting.
|
|
46
|
+
|
|
47
|
+
if (React.Children.toArray(children).some((el) => isValidElement(el))) {
|
|
48
|
+
return (
|
|
49
|
+
<Highlight
|
|
50
|
+
{...defaultProps}
|
|
51
|
+
key={String(mounted)}
|
|
52
|
+
theme={prismTheme}
|
|
53
|
+
code=""
|
|
54
|
+
language={'text'}>
|
|
55
|
+
{({className, style}) => (
|
|
56
|
+
<pre
|
|
57
|
+
/* eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex */
|
|
58
|
+
tabIndex={0}
|
|
59
|
+
className={clsx(
|
|
60
|
+
className,
|
|
61
|
+
styles.codeBlockStandalone,
|
|
62
|
+
'thin-scrollbar',
|
|
63
|
+
styles.codeBlockContainer,
|
|
64
|
+
blockClassName,
|
|
65
|
+
ThemeClassNames.common.codeBlock,
|
|
66
|
+
)}
|
|
67
|
+
style={style}>
|
|
68
|
+
<code className={styles.codeBlockLines}>{children}</code>
|
|
69
|
+
</pre>
|
|
70
|
+
)}
|
|
71
|
+
</Highlight>
|
|
72
|
+
);
|
|
73
|
+
} // The children is now guaranteed to be one/more plain strings
|
|
45
74
|
|
|
46
75
|
const content = Array.isArray(children) ? children.join('') : children;
|
|
47
76
|
const language = parseLanguage(blockClassName) ?? prism.defaultLanguage;
|
|
@@ -59,7 +88,7 @@ export default function CodeBlock({
|
|
|
59
88
|
key={String(mounted)}
|
|
60
89
|
theme={prismTheme}
|
|
61
90
|
code={code}
|
|
62
|
-
language={language}>
|
|
91
|
+
language={language ?? 'text'}>
|
|
63
92
|
{({className, style, tokens, getLineProps, getTokenProps}) => (
|
|
64
93
|
<div
|
|
65
94
|
className={clsx(
|
|
@@ -30,35 +30,22 @@ const MDXComponents = {
|
|
|
30
30
|
return <Head {...props}>{unwrappedChildren}</Head>;
|
|
31
31
|
},
|
|
32
32
|
code: (props) => {
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (isValidElement(children)) {
|
|
37
|
-
return children;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return !children.includes('\n') ? (
|
|
41
|
-
<code {...props} />
|
|
42
|
-
) : (
|
|
43
|
-
<CodeBlock {...props} />
|
|
33
|
+
const shouldBeInline = React.Children.toArray(props.children).every(
|
|
34
|
+
(el) => typeof el === 'string' && !el.includes('\n'),
|
|
44
35
|
);
|
|
36
|
+
return shouldBeInline ? <code {...props} /> : <CodeBlock {...props} />;
|
|
45
37
|
},
|
|
46
38
|
a: (props) => <Link {...props} />,
|
|
47
|
-
pre: (props) =>
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
<CodeBlock
|
|
56
|
-
{...(isValidElement(children) ? children?.props : {...props})}
|
|
57
|
-
/>
|
|
58
|
-
);
|
|
59
|
-
},
|
|
39
|
+
pre: (props) => (
|
|
40
|
+
<CodeBlock // If this pre is created by a ``` fenced codeblock, unwrap the children
|
|
41
|
+
{...(isValidElement(props.children) &&
|
|
42
|
+
props.children.props.originalType === 'code'
|
|
43
|
+
? props.children?.props
|
|
44
|
+
: {...props})}
|
|
45
|
+
/>
|
|
46
|
+
),
|
|
60
47
|
details: (props) => {
|
|
61
|
-
const items = React.Children.toArray(props.children); // Split summary item from the rest to pass it as a separate prop to the
|
|
48
|
+
const items = React.Children.toArray(props.children); // Split summary item from the rest to pass it as a separate prop to the Details theme component
|
|
62
49
|
|
|
63
50
|
const summary = items.find((item) => item?.props?.mdxType === 'summary');
|
|
64
51
|
const children = <>{items.filter((item) => item !== summary)}</>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/theme-classic",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-4330",
|
|
4
4
|
"description": "Classic theme for Docusaurus",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "src/theme-classic.d.ts",
|
|
@@ -23,14 +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/theme-translations": "0.0.0-
|
|
32
|
-
"@docusaurus/utils": "0.0.0-
|
|
33
|
-
"@docusaurus/utils-validation": "0.0.0-
|
|
26
|
+
"@docusaurus/core": "0.0.0-4330",
|
|
27
|
+
"@docusaurus/plugin-content-blog": "0.0.0-4330",
|
|
28
|
+
"@docusaurus/plugin-content-docs": "0.0.0-4330",
|
|
29
|
+
"@docusaurus/plugin-content-pages": "0.0.0-4330",
|
|
30
|
+
"@docusaurus/theme-common": "0.0.0-4330",
|
|
31
|
+
"@docusaurus/theme-translations": "0.0.0-4330",
|
|
32
|
+
"@docusaurus/utils": "0.0.0-4330",
|
|
33
|
+
"@docusaurus/utils-validation": "0.0.0-4330",
|
|
34
34
|
"@mdx-js/mdx": "^1.6.21",
|
|
35
35
|
"@mdx-js/react": "^1.6.21",
|
|
36
36
|
"clsx": "^1.1.1",
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"rtlcss": "^3.3.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@docusaurus/module-type-aliases": "0.0.0-
|
|
49
|
-
"@docusaurus/types": "0.0.0-
|
|
48
|
+
"@docusaurus/module-type-aliases": "0.0.0-4330",
|
|
49
|
+
"@docusaurus/types": "0.0.0-4330",
|
|
50
50
|
"@types/mdx-js__react": "^1.5.4",
|
|
51
51
|
"@types/parse-numeric-range": "^0.0.1",
|
|
52
52
|
"@types/rtlcss": "^3.1.1",
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
"engines": {
|
|
62
62
|
"node": ">=14"
|
|
63
63
|
},
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "ed4c0b5a082b72f8576bd7f7286dfb1a5c295edd"
|
|
65
65
|
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import React, {useEffect, useState} from 'react';
|
|
8
|
+
import React, {isValidElement, 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';
|
|
@@ -49,13 +49,44 @@ export default function CodeBlock({
|
|
|
49
49
|
const codeBlockTitle = parseCodeBlockTitle(metastring) || title;
|
|
50
50
|
const prismTheme = usePrismTheme();
|
|
51
51
|
|
|
52
|
-
//
|
|
52
|
+
// <pre> tags in markdown map to CodeBlocks and they may contain JSX children.
|
|
53
|
+
// When the children is not a simple string, we just return a styled block without actually highlighting.
|
|
54
|
+
if (React.Children.toArray(children).some((el) => isValidElement(el))) {
|
|
55
|
+
return (
|
|
56
|
+
<Highlight
|
|
57
|
+
{...defaultProps}
|
|
58
|
+
key={String(mounted)}
|
|
59
|
+
theme={prismTheme}
|
|
60
|
+
code=""
|
|
61
|
+
language={'text' as Language}>
|
|
62
|
+
{({className, style}) => (
|
|
63
|
+
<pre
|
|
64
|
+
/* eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex */
|
|
65
|
+
tabIndex={0}
|
|
66
|
+
className={clsx(
|
|
67
|
+
className,
|
|
68
|
+
styles.codeBlockStandalone,
|
|
69
|
+
'thin-scrollbar',
|
|
70
|
+
styles.codeBlockContainer,
|
|
71
|
+
blockClassName,
|
|
72
|
+
ThemeClassNames.common.codeBlock,
|
|
73
|
+
)}
|
|
74
|
+
style={style}>
|
|
75
|
+
<code className={styles.codeBlockLines}>{children}</code>
|
|
76
|
+
</pre>
|
|
77
|
+
)}
|
|
78
|
+
</Highlight>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// The children is now guaranteed to be one/more plain strings
|
|
53
83
|
const content = Array.isArray(children)
|
|
54
84
|
? children.join('')
|
|
55
85
|
: (children as string);
|
|
56
86
|
|
|
57
87
|
const language =
|
|
58
|
-
parseLanguage(blockClassName) ??
|
|
88
|
+
parseLanguage(blockClassName) ??
|
|
89
|
+
(prism.defaultLanguage as Language | undefined);
|
|
59
90
|
const {highlightLines, code} = parseLines(content, metastring, language);
|
|
60
91
|
|
|
61
92
|
const handleCopyCode = () => {
|
|
@@ -71,7 +102,7 @@ export default function CodeBlock({
|
|
|
71
102
|
key={String(mounted)}
|
|
72
103
|
theme={prismTheme}
|
|
73
104
|
code={code}
|
|
74
|
-
language={language}>
|
|
105
|
+
language={language ?? ('text' as Language)}>
|
|
75
106
|
{({className, style, tokens, getLineProps, getTokenProps}) => (
|
|
76
107
|
<div
|
|
77
108
|
className={clsx(
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import React, {ComponentProps, isValidElement, ReactElement} from 'react';
|
|
9
9
|
import Head from '@docusaurus/Head';
|
|
10
10
|
import Link from '@docusaurus/Link';
|
|
11
|
-
import CodeBlock
|
|
11
|
+
import CodeBlock from '@theme/CodeBlock';
|
|
12
12
|
import Heading from '@theme/Heading';
|
|
13
13
|
import Details from '@theme/Details';
|
|
14
14
|
import type {MDXComponentsObject} from '@theme/MDXComponents';
|
|
@@ -33,40 +33,25 @@ const MDXComponents: MDXComponentsObject = {
|
|
|
33
33
|
return <Head {...props}>{unwrappedChildren}</Head>;
|
|
34
34
|
},
|
|
35
35
|
code: (props) => {
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
// For retrocompatibility purposes (pretty rare use case)
|
|
39
|
-
// See https://github.com/facebook/docusaurus/pull/1584
|
|
40
|
-
if (isValidElement(children)) {
|
|
41
|
-
return children;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return !children.includes('\n') ? (
|
|
45
|
-
<code {...props} />
|
|
46
|
-
) : (
|
|
47
|
-
<CodeBlock {...props} />
|
|
36
|
+
const shouldBeInline = React.Children.toArray(props.children).every(
|
|
37
|
+
(el) => typeof el === 'string' && !el.includes('\n'),
|
|
48
38
|
);
|
|
49
|
-
},
|
|
50
|
-
a: (props) => <Link {...props} />,
|
|
51
|
-
pre: (props) => {
|
|
52
|
-
const {children} = props;
|
|
53
39
|
|
|
54
|
-
|
|
55
|
-
if (isValidElement(children) && isValidElement(children?.props?.children)) {
|
|
56
|
-
return children.props.children;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return (
|
|
60
|
-
<CodeBlock
|
|
61
|
-
{...((isValidElement(children)
|
|
62
|
-
? children?.props
|
|
63
|
-
: {...props}) as Props)}
|
|
64
|
-
/>
|
|
65
|
-
);
|
|
40
|
+
return shouldBeInline ? <code {...props} /> : <CodeBlock {...props} />;
|
|
66
41
|
},
|
|
42
|
+
a: (props) => <Link {...props} />,
|
|
43
|
+
pre: (props) => (
|
|
44
|
+
<CodeBlock
|
|
45
|
+
// If this pre is created by a ``` fenced codeblock, unwrap the children
|
|
46
|
+
{...(isValidElement(props.children) &&
|
|
47
|
+
props.children.props.originalType === 'code'
|
|
48
|
+
? props.children?.props
|
|
49
|
+
: {...props})}
|
|
50
|
+
/>
|
|
51
|
+
),
|
|
67
52
|
details: (props): JSX.Element => {
|
|
68
53
|
const items = React.Children.toArray(props.children) as ReactElement[];
|
|
69
|
-
// Split summary item from the rest to pass it as a separate prop to the
|
|
54
|
+
// Split summary item from the rest to pass it as a separate prop to the Details theme component
|
|
70
55
|
const summary: ReactElement<ComponentProps<'summary'>> = items.find(
|
|
71
56
|
(item) => item?.props?.mdxType === 'summary',
|
|
72
57
|
)!;
|