@docusaurus/theme-classic 0.0.0-4866 → 0.0.0-4871
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/admonitions.css +4 -0
- package/lib/theme-classic.d.ts +65 -3
- package/lib/validateThemeConfig.js +12 -0
- package/lib-next/theme/CodeBlock/Container/index.js +29 -0
- package/lib-next/theme/CodeBlock/Container/styles.module.css +14 -0
- package/lib-next/theme/CodeBlock/Content/Element.js +23 -0
- package/lib-next/theme/CodeBlock/Content/String.js +87 -0
- package/lib-next/theme/CodeBlock/{styles.module.css → Content/styles.module.css} +0 -36
- package/lib-next/theme/CodeBlock/Line/index.js +55 -0
- package/lib-next/theme/CodeBlock/Line/styles.module.css +34 -0
- package/lib-next/theme/CodeBlock/index.js +27 -157
- package/lib-next/theme/NavbarItem/HtmlNavbarItem.js +30 -0
- package/lib-next/theme/NavbarItem/index.js +2 -0
- package/package.json +13 -13
- package/src/admonitions.css +4 -0
- package/src/theme/CodeBlock/Container/index.tsx +35 -0
- package/src/theme/CodeBlock/Container/styles.module.css +14 -0
- package/src/theme/CodeBlock/Content/Element.tsx +30 -0
- package/src/theme/CodeBlock/Content/String.tsx +94 -0
- package/src/theme/CodeBlock/{styles.module.css → Content/styles.module.css} +0 -36
- package/src/theme/CodeBlock/Line/index.tsx +51 -0
- package/src/theme/CodeBlock/Line/styles.module.css +34 -0
- package/src/theme/CodeBlock/index.tsx +29 -160
- package/src/theme/NavbarItem/HtmlNavbarItem.tsx +32 -0
- package/src/theme/NavbarItem/index.tsx +2 -0
- package/src/theme-classic.d.ts +65 -3
- package/src/validateThemeConfig.ts +14 -0
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-4871",
|
|
4
4
|
"description": "Classic theme for Docusaurus",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "src/theme-classic.d.ts",
|
|
@@ -21,15 +21,15 @@
|
|
|
21
21
|
"format:lib-next": "prettier --config ../../.prettierrc --write \"lib-next/**/*.{js,ts,jsx,tsc}\""
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@docusaurus/core": "0.0.0-
|
|
25
|
-
"@docusaurus/plugin-content-blog": "0.0.0-
|
|
26
|
-
"@docusaurus/plugin-content-docs": "0.0.0-
|
|
27
|
-
"@docusaurus/plugin-content-pages": "0.0.0-
|
|
28
|
-
"@docusaurus/theme-common": "0.0.0-
|
|
29
|
-
"@docusaurus/theme-translations": "0.0.0-
|
|
30
|
-
"@docusaurus/utils": "0.0.0-
|
|
31
|
-
"@docusaurus/utils-common": "0.0.0-
|
|
32
|
-
"@docusaurus/utils-validation": "0.0.0-
|
|
24
|
+
"@docusaurus/core": "0.0.0-4871",
|
|
25
|
+
"@docusaurus/plugin-content-blog": "0.0.0-4871",
|
|
26
|
+
"@docusaurus/plugin-content-docs": "0.0.0-4871",
|
|
27
|
+
"@docusaurus/plugin-content-pages": "0.0.0-4871",
|
|
28
|
+
"@docusaurus/theme-common": "0.0.0-4871",
|
|
29
|
+
"@docusaurus/theme-translations": "0.0.0-4871",
|
|
30
|
+
"@docusaurus/utils": "0.0.0-4871",
|
|
31
|
+
"@docusaurus/utils-common": "0.0.0-4871",
|
|
32
|
+
"@docusaurus/utils-validation": "0.0.0-4871",
|
|
33
33
|
"@mdx-js/react": "^1.6.22",
|
|
34
34
|
"clsx": "^1.1.1",
|
|
35
35
|
"copy-text-to-clipboard": "^3.0.1",
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"@babel/cli": "^7.17.6",
|
|
46
46
|
"@babel/core": "^7.17.9",
|
|
47
47
|
"@babel/preset-typescript": "^7.16.7",
|
|
48
|
-
"@docusaurus/module-type-aliases": "0.0.0-
|
|
49
|
-
"@docusaurus/types": "0.0.0-
|
|
48
|
+
"@docusaurus/module-type-aliases": "0.0.0-4871",
|
|
49
|
+
"@docusaurus/types": "0.0.0-4871",
|
|
50
50
|
"@types/mdx-js__react": "^1.5.5",
|
|
51
51
|
"@types/prismjs": "^1.26.0",
|
|
52
52
|
"@types/rtlcss": "^3.1.3",
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"engines": {
|
|
63
63
|
"node": ">=14"
|
|
64
64
|
},
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "d8f14db917aa6048c52018f69da5486e5813b02e"
|
|
66
66
|
}
|
package/src/admonitions.css
CHANGED
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
import React, {type ComponentProps} from 'react';
|
|
9
|
+
import clsx from 'clsx';
|
|
10
|
+
import {
|
|
11
|
+
usePrismTheme,
|
|
12
|
+
getPrismCssVariables,
|
|
13
|
+
ThemeClassNames,
|
|
14
|
+
} from '@docusaurus/theme-common';
|
|
15
|
+
import styles from './styles.module.css';
|
|
16
|
+
|
|
17
|
+
export default function CodeBlockContainer<T extends 'div' | 'pre'>({
|
|
18
|
+
as: As,
|
|
19
|
+
...props
|
|
20
|
+
}: {as: T} & ComponentProps<T>): JSX.Element {
|
|
21
|
+
const prismTheme = usePrismTheme();
|
|
22
|
+
const prismCssVariables = getPrismCssVariables(prismTheme);
|
|
23
|
+
return (
|
|
24
|
+
<As
|
|
25
|
+
// Polymorphic components are hard to type, without `oneOf` generics
|
|
26
|
+
{...(props as never)}
|
|
27
|
+
style={prismCssVariables}
|
|
28
|
+
className={clsx(
|
|
29
|
+
props.className,
|
|
30
|
+
styles.codeBlockContainer,
|
|
31
|
+
ThemeClassNames.common.codeBlock,
|
|
32
|
+
)}
|
|
33
|
+
/>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
.codeBlockContainer {
|
|
9
|
+
background: var(--prism-background-color);
|
|
10
|
+
color: var(--prism-color);
|
|
11
|
+
margin-bottom: var(--ifm-leading);
|
|
12
|
+
box-shadow: var(--ifm-global-shadow-lw);
|
|
13
|
+
border-radius: var(--ifm-code-border-radius);
|
|
14
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
import React from 'react';
|
|
9
|
+
import Container from '@theme/CodeBlock/Container';
|
|
10
|
+
import clsx from 'clsx';
|
|
11
|
+
import type {Props} from '@theme/CodeBlock/Content/Element';
|
|
12
|
+
|
|
13
|
+
import styles from './styles.module.css';
|
|
14
|
+
|
|
15
|
+
// <pre> tags in markdown map to CodeBlocks. They may contain JSX children. When
|
|
16
|
+
// the children is not a simple string, we just return a styled block without
|
|
17
|
+
// actually highlighting.
|
|
18
|
+
export default function CodeBlockJSX({
|
|
19
|
+
children,
|
|
20
|
+
className,
|
|
21
|
+
}: Props): JSX.Element {
|
|
22
|
+
return (
|
|
23
|
+
<Container
|
|
24
|
+
as="pre"
|
|
25
|
+
tabIndex={0}
|
|
26
|
+
className={clsx(styles.codeBlockStandalone, 'thin-scrollbar', className)}>
|
|
27
|
+
<code className={styles.codeBlockLines}>{children}</code>
|
|
28
|
+
</Container>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
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
|
+
import React from 'react';
|
|
9
|
+
import {
|
|
10
|
+
useThemeConfig,
|
|
11
|
+
parseCodeBlockTitle,
|
|
12
|
+
parseLanguage,
|
|
13
|
+
parseLines,
|
|
14
|
+
containsLineNumbers,
|
|
15
|
+
usePrismTheme,
|
|
16
|
+
} from '@docusaurus/theme-common';
|
|
17
|
+
import clsx from 'clsx';
|
|
18
|
+
import Highlight, {defaultProps, type Language} from 'prism-react-renderer';
|
|
19
|
+
import Line from '@theme/CodeBlock/Line';
|
|
20
|
+
import CopyButton from '@theme/CodeBlock/CopyButton';
|
|
21
|
+
import Container from '@theme/CodeBlock/Container';
|
|
22
|
+
import type {Props} from '@theme/CodeBlock/Content/String';
|
|
23
|
+
|
|
24
|
+
import styles from './styles.module.css';
|
|
25
|
+
|
|
26
|
+
export default function CodeBlockString({
|
|
27
|
+
children,
|
|
28
|
+
className: blockClassName = '',
|
|
29
|
+
metastring,
|
|
30
|
+
title: titleProp,
|
|
31
|
+
showLineNumbers: showLineNumbersProp,
|
|
32
|
+
language: languageProp,
|
|
33
|
+
}: Props): JSX.Element {
|
|
34
|
+
const {
|
|
35
|
+
prism: {defaultLanguage},
|
|
36
|
+
} = useThemeConfig();
|
|
37
|
+
const language =
|
|
38
|
+
languageProp ?? parseLanguage(blockClassName) ?? defaultLanguage;
|
|
39
|
+
const prismTheme = usePrismTheme();
|
|
40
|
+
|
|
41
|
+
// We still parse the metastring in case we want to support more syntax in the
|
|
42
|
+
// future. Note that MDX doesn't strip quotes when parsing metastring:
|
|
43
|
+
// "title=\"xyz\"" => title: "\"xyz\""
|
|
44
|
+
const title = parseCodeBlockTitle(metastring) || titleProp;
|
|
45
|
+
|
|
46
|
+
const {highlightLines, code} = parseLines(children, metastring, language);
|
|
47
|
+
const showLineNumbers =
|
|
48
|
+
showLineNumbersProp || containsLineNumbers(metastring);
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<Container
|
|
52
|
+
as="div"
|
|
53
|
+
className={clsx(
|
|
54
|
+
blockClassName,
|
|
55
|
+
language &&
|
|
56
|
+
!blockClassName.includes(`language-${language}`) &&
|
|
57
|
+
`language-${language}`,
|
|
58
|
+
)}>
|
|
59
|
+
{title && <div className={styles.codeBlockTitle}>{title}</div>}
|
|
60
|
+
<div className={styles.codeBlockContent}>
|
|
61
|
+
<Highlight
|
|
62
|
+
{...defaultProps}
|
|
63
|
+
theme={prismTheme}
|
|
64
|
+
code={code}
|
|
65
|
+
language={(language ?? 'text') as Language}>
|
|
66
|
+
{({className, tokens, getLineProps, getTokenProps}) => (
|
|
67
|
+
<pre
|
|
68
|
+
/* eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex */
|
|
69
|
+
tabIndex={0}
|
|
70
|
+
className={clsx(className, styles.codeBlock, 'thin-scrollbar')}>
|
|
71
|
+
<code
|
|
72
|
+
className={clsx(
|
|
73
|
+
styles.codeBlockLines,
|
|
74
|
+
showLineNumbers && styles.codeBlockLinesWithNumbering,
|
|
75
|
+
)}>
|
|
76
|
+
{tokens.map((line, i) => (
|
|
77
|
+
<Line
|
|
78
|
+
key={i}
|
|
79
|
+
line={line}
|
|
80
|
+
getLineProps={getLineProps}
|
|
81
|
+
getTokenProps={getTokenProps}
|
|
82
|
+
highlight={highlightLines.includes(i)}
|
|
83
|
+
showLineNumbers={showLineNumbers}
|
|
84
|
+
/>
|
|
85
|
+
))}
|
|
86
|
+
</code>
|
|
87
|
+
</pre>
|
|
88
|
+
)}
|
|
89
|
+
</Highlight>
|
|
90
|
+
<CopyButton code={code} />
|
|
91
|
+
</div>
|
|
92
|
+
</Container>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
@@ -5,14 +5,6 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
.codeBlockContainer {
|
|
9
|
-
background: var(--prism-background-color);
|
|
10
|
-
color: var(--prism-color);
|
|
11
|
-
margin-bottom: var(--ifm-leading);
|
|
12
|
-
box-shadow: var(--ifm-global-shadow-lw);
|
|
13
|
-
border-radius: var(--ifm-code-border-radius);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
8
|
.codeBlockContent {
|
|
17
9
|
position: relative;
|
|
18
10
|
/* rtl:ignore */
|
|
@@ -62,31 +54,3 @@
|
|
|
62
54
|
white-space: pre-wrap;
|
|
63
55
|
}
|
|
64
56
|
}
|
|
65
|
-
|
|
66
|
-
.codeLine {
|
|
67
|
-
display: table-row;
|
|
68
|
-
counter-increment: line-count;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
.codeLineNumber {
|
|
72
|
-
display: table-cell;
|
|
73
|
-
text-align: right;
|
|
74
|
-
width: 1%;
|
|
75
|
-
position: sticky;
|
|
76
|
-
left: 0;
|
|
77
|
-
padding: 0 var(--ifm-pre-padding);
|
|
78
|
-
background: var(--ifm-pre-background);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
.codeLineNumber::before {
|
|
82
|
-
content: counter(line-count);
|
|
83
|
-
opacity: 0.4;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
:global(.docusaurus-highlight-code-line) .codeLineNumber::before {
|
|
87
|
-
opacity: 0.8;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
.codeLineContent {
|
|
91
|
-
padding-right: var(--ifm-pre-padding);
|
|
92
|
-
}
|
|
@@ -0,0 +1,51 @@
|
|
|
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
|
+
import React from 'react';
|
|
9
|
+
import type {Props} from '@theme/CodeBlock/Line';
|
|
10
|
+
import styles from './styles.module.css';
|
|
11
|
+
|
|
12
|
+
export default function CodeBlockLine({
|
|
13
|
+
line,
|
|
14
|
+
highlight,
|
|
15
|
+
showLineNumbers,
|
|
16
|
+
getLineProps,
|
|
17
|
+
getTokenProps,
|
|
18
|
+
}: Props): JSX.Element {
|
|
19
|
+
if (line.length === 1 && line[0]!.content === '\n') {
|
|
20
|
+
line[0]!.content = '';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const lineProps = getLineProps({
|
|
24
|
+
line,
|
|
25
|
+
...(showLineNumbers && {className: styles.codeLine}),
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
if (highlight) {
|
|
29
|
+
lineProps.className += ' docusaurus-highlight-code-line';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const lineTokens = line.map((token, key) => (
|
|
33
|
+
<span key={key} {...getTokenProps({token, key})} />
|
|
34
|
+
));
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<span {...lineProps}>
|
|
38
|
+
{showLineNumbers ? (
|
|
39
|
+
<>
|
|
40
|
+
<span className={styles.codeLineNumber} />
|
|
41
|
+
<span className={styles.codeLineContent}>{lineTokens}</span>
|
|
42
|
+
</>
|
|
43
|
+
) : (
|
|
44
|
+
<>
|
|
45
|
+
{lineTokens}
|
|
46
|
+
<br />
|
|
47
|
+
</>
|
|
48
|
+
)}
|
|
49
|
+
</span>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
.codeLine {
|
|
9
|
+
display: table-row;
|
|
10
|
+
counter-increment: line-count;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.codeLineNumber {
|
|
14
|
+
display: table-cell;
|
|
15
|
+
text-align: right;
|
|
16
|
+
width: 1%;
|
|
17
|
+
position: sticky;
|
|
18
|
+
left: 0;
|
|
19
|
+
padding: 0 var(--ifm-pre-padding);
|
|
20
|
+
background: var(--ifm-pre-background);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.codeLineNumber::before {
|
|
24
|
+
content: counter(line-count);
|
|
25
|
+
opacity: 0.4;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
:global(.docusaurus-highlight-code-line) .codeLineNumber::before {
|
|
29
|
+
opacity: 0.8;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.codeLineContent {
|
|
33
|
+
padding-right: var(--ifm-pre-padding);
|
|
34
|
+
}
|
|
@@ -5,172 +5,41 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import React, {isValidElement,
|
|
9
|
-
import
|
|
10
|
-
import Highlight, {defaultProps, type Language} from 'prism-react-renderer';
|
|
11
|
-
import {
|
|
12
|
-
useThemeConfig,
|
|
13
|
-
parseCodeBlockTitle,
|
|
14
|
-
parseLanguage,
|
|
15
|
-
parseLines,
|
|
16
|
-
containsLineNumbers,
|
|
17
|
-
ThemeClassNames,
|
|
18
|
-
usePrismTheme,
|
|
19
|
-
getPrismCssVariables,
|
|
20
|
-
} from '@docusaurus/theme-common';
|
|
21
|
-
import CopyButton from '@theme/CodeBlock/CopyButton';
|
|
8
|
+
import React, {isValidElement, type ReactNode} from 'react';
|
|
9
|
+
import useIsBrowser from '@docusaurus/useIsBrowser';
|
|
22
10
|
import type {Props} from '@theme/CodeBlock';
|
|
11
|
+
import ElementContent from '@theme/CodeBlock/Content/Element';
|
|
12
|
+
import StringContent from '@theme/CodeBlock/Content/String';
|
|
23
13
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
showLineNumbers,
|
|
32
|
-
language: languageProp,
|
|
33
|
-
}: Props): JSX.Element {
|
|
34
|
-
const {prism} = useThemeConfig();
|
|
35
|
-
|
|
36
|
-
const [mounted, setMounted] = useState(false);
|
|
37
|
-
// The Prism theme on SSR is always the default theme but the site theme
|
|
38
|
-
// can be in a different mode. React hydration doesn't update DOM styles
|
|
39
|
-
// that come from SSR. Hence force a re-render after mounting to apply the
|
|
40
|
-
// current relevant styles. There will be a flash seen of the original
|
|
41
|
-
// styles seen using this current approach but that's probably ok. Fixing
|
|
42
|
-
// the flash will require changing the theming approach and is not worth it
|
|
43
|
-
// at this point.
|
|
44
|
-
useEffect(() => {
|
|
45
|
-
setMounted(true);
|
|
46
|
-
}, []);
|
|
47
|
-
|
|
48
|
-
// We still parse the metastring in case we want to support more syntax in the
|
|
49
|
-
// future. Note that MDX doesn't strip quotes when parsing metastring:
|
|
50
|
-
// "title=\"xyz\"" => title: "\"xyz\""
|
|
51
|
-
const codeBlockTitle = parseCodeBlockTitle(metastring) || title;
|
|
52
|
-
const prismTheme = usePrismTheme();
|
|
53
|
-
|
|
54
|
-
const prismCssVariables = getPrismCssVariables(prismTheme);
|
|
55
|
-
|
|
56
|
-
// <pre> tags in markdown map to CodeBlocks and they may contain JSX children.
|
|
57
|
-
// When the children is not a simple string, we just return a styled block
|
|
58
|
-
// without actually highlighting.
|
|
14
|
+
/**
|
|
15
|
+
* Best attempt to make the children a plain string so it is copyable. If there
|
|
16
|
+
* are react elements, we will not be able to copy the content, and it will
|
|
17
|
+
* return `children` as-is; otherwise, it concatenates the string children
|
|
18
|
+
* together.
|
|
19
|
+
*/
|
|
20
|
+
function maybeStringifyChildren(children: ReactNode): ReactNode {
|
|
59
21
|
if (React.Children.toArray(children).some((el) => isValidElement(el))) {
|
|
60
|
-
return
|
|
61
|
-
<Highlight
|
|
62
|
-
{...defaultProps}
|
|
63
|
-
key={String(mounted)}
|
|
64
|
-
theme={prismTheme}
|
|
65
|
-
code=""
|
|
66
|
-
language={'text' as Language}>
|
|
67
|
-
{({className}) => (
|
|
68
|
-
<pre
|
|
69
|
-
/* eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex */
|
|
70
|
-
tabIndex={0}
|
|
71
|
-
className={clsx(
|
|
72
|
-
className,
|
|
73
|
-
styles.codeBlockStandalone,
|
|
74
|
-
'thin-scrollbar',
|
|
75
|
-
styles.codeBlockContainer,
|
|
76
|
-
blockClassName,
|
|
77
|
-
ThemeClassNames.common.codeBlock,
|
|
78
|
-
)}
|
|
79
|
-
style={prismCssVariables}>
|
|
80
|
-
<code className={styles.codeBlockLines}>{children}</code>
|
|
81
|
-
</pre>
|
|
82
|
-
)}
|
|
83
|
-
</Highlight>
|
|
84
|
-
);
|
|
22
|
+
return children;
|
|
85
23
|
}
|
|
86
|
-
|
|
87
24
|
// The children is now guaranteed to be one/more plain strings
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
: (children as string);
|
|
91
|
-
|
|
92
|
-
const language =
|
|
93
|
-
languageProp ?? parseLanguage(blockClassName) ?? prism.defaultLanguage;
|
|
94
|
-
const {highlightLines, code} = parseLines(content, metastring, language);
|
|
95
|
-
const shouldShowLineNumbers =
|
|
96
|
-
showLineNumbers || containsLineNumbers(metastring);
|
|
25
|
+
return Array.isArray(children) ? children.join('') : (children as string);
|
|
26
|
+
}
|
|
97
27
|
|
|
28
|
+
export default function CodeBlock({
|
|
29
|
+
children: rawChildren,
|
|
30
|
+
...props
|
|
31
|
+
}: Props): JSX.Element {
|
|
32
|
+
// The Prism theme on SSR is always the default theme but the site theme can
|
|
33
|
+
// be in a different mode. React hydration doesn't update DOM styles that come
|
|
34
|
+
// from SSR. Hence force a re-render after mounting to apply the current
|
|
35
|
+
// relevant styles.
|
|
36
|
+
const isBrowser = useIsBrowser();
|
|
37
|
+
const children = maybeStringifyChildren(rawChildren);
|
|
38
|
+
const CodeBlockComp =
|
|
39
|
+
typeof children === 'string' ? StringContent : ElementContent;
|
|
98
40
|
return (
|
|
99
|
-
<
|
|
100
|
-
{
|
|
101
|
-
|
|
102
|
-
theme={prismTheme}
|
|
103
|
-
code={code}
|
|
104
|
-
language={(language ?? 'text') as Language}>
|
|
105
|
-
{({className, tokens, getLineProps, getTokenProps}) => (
|
|
106
|
-
<div
|
|
107
|
-
className={clsx(
|
|
108
|
-
styles.codeBlockContainer,
|
|
109
|
-
blockClassName,
|
|
110
|
-
{
|
|
111
|
-
[`language-${language}`]:
|
|
112
|
-
language && !blockClassName.includes(`language-${language}`),
|
|
113
|
-
},
|
|
114
|
-
ThemeClassNames.common.codeBlock,
|
|
115
|
-
)}
|
|
116
|
-
style={prismCssVariables}>
|
|
117
|
-
{codeBlockTitle && (
|
|
118
|
-
<div className={styles.codeBlockTitle}>{codeBlockTitle}</div>
|
|
119
|
-
)}
|
|
120
|
-
<div className={styles.codeBlockContent}>
|
|
121
|
-
<pre
|
|
122
|
-
/* eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex */
|
|
123
|
-
tabIndex={0}
|
|
124
|
-
className={clsx(className, styles.codeBlock, 'thin-scrollbar')}>
|
|
125
|
-
<code
|
|
126
|
-
className={clsx(
|
|
127
|
-
styles.codeBlockLines,
|
|
128
|
-
shouldShowLineNumbers && styles.codeBlockLinesWithNumbering,
|
|
129
|
-
)}>
|
|
130
|
-
{tokens.map((line, i) => {
|
|
131
|
-
if (line.length === 1 && line[0]!.content === '\n') {
|
|
132
|
-
line[0]!.content = '';
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
const lineProps = getLineProps({
|
|
136
|
-
line,
|
|
137
|
-
key: i,
|
|
138
|
-
...(shouldShowLineNumbers && {className: styles.codeLine}),
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
if (highlightLines.includes(i)) {
|
|
142
|
-
lineProps.className += ' docusaurus-highlight-code-line';
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
const lineTokens = line.map((token, key) => (
|
|
146
|
-
<span key={key} {...getTokenProps({token, key})} />
|
|
147
|
-
));
|
|
148
|
-
|
|
149
|
-
return (
|
|
150
|
-
<span key={i} {...lineProps}>
|
|
151
|
-
{shouldShowLineNumbers ? (
|
|
152
|
-
<>
|
|
153
|
-
<span className={styles.codeLineNumber} />
|
|
154
|
-
<span className={styles.codeLineContent}>
|
|
155
|
-
{lineTokens}
|
|
156
|
-
</span>
|
|
157
|
-
</>
|
|
158
|
-
) : (
|
|
159
|
-
<>
|
|
160
|
-
{lineTokens}
|
|
161
|
-
<br />
|
|
162
|
-
</>
|
|
163
|
-
)}
|
|
164
|
-
</span>
|
|
165
|
-
);
|
|
166
|
-
})}
|
|
167
|
-
</code>
|
|
168
|
-
</pre>
|
|
169
|
-
|
|
170
|
-
<CopyButton code={code} />
|
|
171
|
-
</div>
|
|
172
|
-
</div>
|
|
173
|
-
)}
|
|
174
|
-
</Highlight>
|
|
41
|
+
<CodeBlockComp key={String(isBrowser)} {...props}>
|
|
42
|
+
{children as string}
|
|
43
|
+
</CodeBlockComp>
|
|
175
44
|
);
|
|
176
45
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
import React from 'react';
|
|
9
|
+
import clsx from 'clsx';
|
|
10
|
+
|
|
11
|
+
import type {Props} from '@theme/NavbarItem/HtmlNavbarItem';
|
|
12
|
+
|
|
13
|
+
export default function HtmlNavbarItem({
|
|
14
|
+
value,
|
|
15
|
+
className,
|
|
16
|
+
mobile = false,
|
|
17
|
+
isDropdownItem = false,
|
|
18
|
+
}: Props): JSX.Element {
|
|
19
|
+
const Comp = isDropdownItem ? 'li' : 'div';
|
|
20
|
+
return (
|
|
21
|
+
<Comp
|
|
22
|
+
className={clsx(
|
|
23
|
+
{
|
|
24
|
+
navbar__item: !mobile && !isDropdownItem,
|
|
25
|
+
'menu__list-item': mobile,
|
|
26
|
+
},
|
|
27
|
+
className,
|
|
28
|
+
)}
|
|
29
|
+
dangerouslySetInnerHTML={{__html: value}}
|
|
30
|
+
/>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
@@ -12,6 +12,7 @@ import DropdownNavbarItem, {
|
|
|
12
12
|
} from '@theme/NavbarItem/DropdownNavbarItem';
|
|
13
13
|
import LocaleDropdownNavbarItem from '@theme/NavbarItem/LocaleDropdownNavbarItem';
|
|
14
14
|
import SearchNavbarItem from '@theme/NavbarItem/SearchNavbarItem';
|
|
15
|
+
import HtmlNavbarItem from '@theme/NavbarItem/HtmlNavbarItem';
|
|
15
16
|
import type {Types, Props} from '@theme/NavbarItem';
|
|
16
17
|
|
|
17
18
|
const NavbarItemComponents: {
|
|
@@ -23,6 +24,7 @@ const NavbarItemComponents: {
|
|
|
23
24
|
localeDropdown: () => LocaleDropdownNavbarItem,
|
|
24
25
|
search: () => SearchNavbarItem,
|
|
25
26
|
dropdown: () => DropdownNavbarItem,
|
|
27
|
+
html: () => HtmlNavbarItem,
|
|
26
28
|
|
|
27
29
|
// Need to lazy load these items as we don't know for sure the docs plugin is
|
|
28
30
|
// loaded. See https://github.com/facebook/docusaurus/issues/3360
|