@docusaurus/theme-classic 0.0.0-4867 → 0.0.0-4872

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.
Files changed (27) hide show
  1. package/lib/theme-classic.d.ts +65 -3
  2. package/lib/validateThemeConfig.js +12 -0
  3. package/lib-next/theme/CodeBlock/Container/index.js +29 -0
  4. package/lib-next/theme/CodeBlock/Container/styles.module.css +14 -0
  5. package/lib-next/theme/CodeBlock/Content/Element.js +23 -0
  6. package/lib-next/theme/CodeBlock/Content/String.js +87 -0
  7. package/lib-next/theme/CodeBlock/{styles.module.css → Content/styles.module.css} +0 -36
  8. package/lib-next/theme/CodeBlock/Line/index.js +55 -0
  9. package/lib-next/theme/CodeBlock/Line/styles.module.css +34 -0
  10. package/lib-next/theme/CodeBlock/index.js +27 -157
  11. package/lib-next/theme/DocBreadcrumbs/index.js +20 -12
  12. package/lib-next/theme/NavbarItem/HtmlNavbarItem.js +30 -0
  13. package/lib-next/theme/NavbarItem/index.js +2 -0
  14. package/package.json +13 -13
  15. package/src/theme/CodeBlock/Container/index.tsx +35 -0
  16. package/src/theme/CodeBlock/Container/styles.module.css +14 -0
  17. package/src/theme/CodeBlock/Content/Element.tsx +30 -0
  18. package/src/theme/CodeBlock/Content/String.tsx +94 -0
  19. package/src/theme/CodeBlock/{styles.module.css → Content/styles.module.css} +0 -36
  20. package/src/theme/CodeBlock/Line/index.tsx +51 -0
  21. package/src/theme/CodeBlock/Line/styles.module.css +34 -0
  22. package/src/theme/CodeBlock/index.tsx +29 -160
  23. package/src/theme/DocBreadcrumbs/index.tsx +20 -12
  24. package/src/theme/NavbarItem/HtmlNavbarItem.tsx +32 -0
  25. package/src/theme/NavbarItem/index.tsx +2 -0
  26. package/src/theme-classic.d.ts +65 -3
  27. package/src/validateThemeConfig.ts +14 -0
@@ -148,10 +148,10 @@ declare module '@theme/BlogLayout' {
148
148
  }
149
149
 
150
150
  declare module '@theme/CodeBlock' {
151
- import type {ReactElement} from 'react';
151
+ import type {ReactNode} from 'react';
152
152
 
153
153
  export interface Props {
154
- readonly children: string | ReactElement;
154
+ readonly children: ReactNode;
155
155
  readonly className?: string;
156
156
  readonly metastring?: string;
157
157
  readonly title?: string;
@@ -170,6 +170,56 @@ declare module '@theme/CodeBlock/CopyButton' {
170
170
  export default function CopyButton(props: Props): JSX.Element;
171
171
  }
172
172
 
173
+ declare module '@theme/CodeBlock/Container' {
174
+ import type {ComponentProps} from 'react';
175
+
176
+ export default function CodeBlockContainer<T extends 'div' | 'pre'>({
177
+ as: As,
178
+ ...props
179
+ }: {as: T} & ComponentProps<T>): JSX.Element;
180
+ }
181
+
182
+ declare module '@theme/CodeBlock/Content/Element' {
183
+ import type {Props} from '@theme/CodeBlock';
184
+
185
+ export type {Props};
186
+
187
+ export default function CodeBlockElementContent(props: Props): JSX.Element;
188
+ }
189
+
190
+ declare module '@theme/CodeBlock/Content/String' {
191
+ import type {Props as CodeBlockProps} from '@theme/CodeBlock';
192
+
193
+ export interface Props extends Omit<CodeBlockProps, 'children'> {
194
+ readonly children: string;
195
+ }
196
+
197
+ export default function CodeBlockStringContent(props: Props): JSX.Element;
198
+ }
199
+
200
+ declare module '@theme/CodeBlock/Line' {
201
+ import type {ComponentProps} from 'react';
202
+ import type Highlight from 'prism-react-renderer';
203
+
204
+ // Lib does not make this easy
205
+ type RenderProps = Parameters<
206
+ ComponentProps<typeof Highlight>['children']
207
+ >[0];
208
+ type GetLineProps = RenderProps['getLineProps'];
209
+ type GetTokenProps = RenderProps['getTokenProps'];
210
+ type Token = RenderProps['tokens'][number][number];
211
+
212
+ export interface Props {
213
+ readonly line: Token[];
214
+ readonly highlight: boolean;
215
+ readonly showLineNumbers: boolean;
216
+ readonly getLineProps: GetLineProps;
217
+ readonly getTokenProps: GetTokenProps;
218
+ }
219
+
220
+ export default function CodeBlockLine(props: Props): JSX.Element;
221
+ }
222
+
173
223
  declare module '@theme/DocCard' {
174
224
  import type {PropSidebarItem} from '@docusaurus/plugin-content-docs';
175
225
 
@@ -822,6 +872,16 @@ declare module '@theme/NavbarItem/DocSidebarNavbarItem' {
822
872
  export default function DocSidebarNavbarItem(props: Props): JSX.Element;
823
873
  }
824
874
 
875
+ declare module '@theme/NavbarItem/HtmlNavbarItem' {
876
+ import type {Props as DefaultNavbarItemProps} from '@theme/NavbarItem/DefaultNavbarItem';
877
+
878
+ export interface Props extends DefaultNavbarItemProps {
879
+ readonly value: string;
880
+ }
881
+
882
+ export default function HtmlNavbarItem(props: Props): JSX.Element;
883
+ }
884
+
825
885
  declare module '@theme/NavbarItem' {
826
886
  import type {ComponentProps} from 'react';
827
887
  import type {Props as DefaultNavbarItemProps} from '@theme/NavbarItem/DefaultNavbarItem';
@@ -832,12 +892,14 @@ declare module '@theme/NavbarItem' {
832
892
  import type {Props as DocsVersionDropdownNavbarItemProps} from '@theme/NavbarItem/DocsVersionDropdownNavbarItem';
833
893
  import type {Props as LocaleDropdownNavbarItemProps} from '@theme/NavbarItem/LocaleDropdownNavbarItem';
834
894
  import type {Props as SearchNavbarItemProps} from '@theme/NavbarItem/SearchNavbarItem';
895
+ import type {Props as HtmlNavbarItemProps} from '@theme/NavbarItem/HtmlNavbarItem';
835
896
 
836
897
  export type LinkLikeNavbarItemProps =
837
898
  | ({readonly type?: 'default'} & DefaultNavbarItemProps)
838
899
  | ({readonly type: 'doc'} & DocNavbarItemProps)
839
900
  | ({readonly type: 'docsVersion'} & DocsVersionNavbarItemProps)
840
- | ({readonly type: 'docSidebar'} & DocSidebarNavbarItemProps);
901
+ | ({readonly type: 'docSidebar'} & DocSidebarNavbarItemProps)
902
+ | ({readonly type: 'html'} & HtmlNavbarItemProps);
841
903
 
842
904
  export type Props = ComponentProps<'a'> & {
843
905
  readonly position?: 'left' | 'right';
@@ -91,6 +91,12 @@ const DocSidebarItemSchema = NavbarItemBaseSchema.append({
91
91
  docsPluginId: _utilsValidation.Joi.string()
92
92
  });
93
93
 
94
+ const HtmlNavbarItemSchema = _utilsValidation.Joi.object({
95
+ className: _utilsValidation.Joi.string(),
96
+ type: _utilsValidation.Joi.string().equal('html').required(),
97
+ value: _utilsValidation.Joi.string().required()
98
+ });
99
+
94
100
  const itemWithType = type => {
95
101
  // because equal(undefined) is not supported :/
96
102
  const typeSchema = type ? _utilsValidation.Joi.string().required().equal(type) : _utilsValidation.Joi.string().forbidden();
@@ -114,6 +120,9 @@ const DropdownSubitemSchema = _utilsValidation.Joi.object({
114
120
  }, {
115
121
  is: itemWithType(undefined),
116
122
  then: DefaultNavbarItemSchema
123
+ }, {
124
+ is: itemWithType('html'),
125
+ then: HtmlNavbarItemSchema
117
126
  }, {
118
127
  is: _utilsValidation.Joi.alternatives().try(itemWithType('dropdown'), itemWithType('docsVersionDropdown'), itemWithType('localeDropdown'), itemWithType('search')),
119
128
  then: _utilsValidation.Joi.forbidden().messages({
@@ -169,6 +178,9 @@ const NavbarItemSchema = _utilsValidation.Joi.object({
169
178
  }, {
170
179
  is: itemWithType('search'),
171
180
  then: SearchItemSchema
181
+ }, {
182
+ is: itemWithType('html'),
183
+ then: HtmlNavbarItemSchema
172
184
  }, {
173
185
  is: itemWithType(undefined),
174
186
  then: _utilsValidation.Joi.object().when('.', {
@@ -0,0 +1,29 @@
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
+ import React from 'react';
8
+ import clsx from 'clsx';
9
+ import {
10
+ usePrismTheme,
11
+ getPrismCssVariables,
12
+ ThemeClassNames,
13
+ } from '@docusaurus/theme-common';
14
+ import styles from './styles.module.css';
15
+ export default function CodeBlockContainer({as: As, ...props}) {
16
+ const prismTheme = usePrismTheme();
17
+ const prismCssVariables = getPrismCssVariables(prismTheme);
18
+ return (
19
+ <As // Polymorphic components are hard to type, without `oneOf` generics
20
+ {...props}
21
+ style={prismCssVariables}
22
+ className={clsx(
23
+ props.className,
24
+ styles.codeBlockContainer,
25
+ ThemeClassNames.common.codeBlock,
26
+ )}
27
+ />
28
+ );
29
+ }
@@ -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,23 @@
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
+ import React from 'react';
8
+ import Container from '@theme/CodeBlock/Container';
9
+ import clsx from 'clsx';
10
+ import styles from './styles.module.css'; // <pre> tags in markdown map to CodeBlocks. They may contain JSX children. When
11
+ // the children is not a simple string, we just return a styled block without
12
+ // actually highlighting.
13
+
14
+ export default function CodeBlockJSX({children, className}) {
15
+ return (
16
+ <Container
17
+ as="pre"
18
+ tabIndex={0}
19
+ className={clsx(styles.codeBlockStandalone, 'thin-scrollbar', className)}>
20
+ <code className={styles.codeBlockLines}>{children}</code>
21
+ </Container>
22
+ );
23
+ }
@@ -0,0 +1,87 @@
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
+ import React from 'react';
8
+ import {
9
+ useThemeConfig,
10
+ parseCodeBlockTitle,
11
+ parseLanguage,
12
+ parseLines,
13
+ containsLineNumbers,
14
+ usePrismTheme,
15
+ } from '@docusaurus/theme-common';
16
+ import clsx from 'clsx';
17
+ import Highlight, {defaultProps} from 'prism-react-renderer';
18
+ import Line from '@theme/CodeBlock/Line';
19
+ import CopyButton from '@theme/CodeBlock/CopyButton';
20
+ import Container from '@theme/CodeBlock/Container';
21
+ import styles from './styles.module.css';
22
+ export default function CodeBlockString({
23
+ children,
24
+ className: blockClassName = '',
25
+ metastring,
26
+ title: titleProp,
27
+ showLineNumbers: showLineNumbersProp,
28
+ language: languageProp,
29
+ }) {
30
+ const {
31
+ prism: {defaultLanguage},
32
+ } = useThemeConfig();
33
+ const language =
34
+ languageProp ?? parseLanguage(blockClassName) ?? defaultLanguage;
35
+ const prismTheme = usePrismTheme(); // We still parse the metastring in case we want to support more syntax in the
36
+ // future. Note that MDX doesn't strip quotes when parsing metastring:
37
+ // "title=\"xyz\"" => title: "\"xyz\""
38
+
39
+ const title = parseCodeBlockTitle(metastring) || titleProp;
40
+ const {highlightLines, code} = parseLines(children, metastring, language);
41
+ const showLineNumbers =
42
+ showLineNumbersProp || containsLineNumbers(metastring);
43
+ return (
44
+ <Container
45
+ as="div"
46
+ className={clsx(
47
+ blockClassName,
48
+ language &&
49
+ !blockClassName.includes(`language-${language}`) &&
50
+ `language-${language}`,
51
+ )}>
52
+ {title && <div className={styles.codeBlockTitle}>{title}</div>}
53
+ <div className={styles.codeBlockContent}>
54
+ <Highlight
55
+ {...defaultProps}
56
+ theme={prismTheme}
57
+ code={code}
58
+ language={language ?? 'text'}>
59
+ {({className, tokens, getLineProps, getTokenProps}) => (
60
+ <pre
61
+ /* eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex */
62
+ tabIndex={0}
63
+ className={clsx(className, styles.codeBlock, 'thin-scrollbar')}>
64
+ <code
65
+ className={clsx(
66
+ styles.codeBlockLines,
67
+ showLineNumbers && styles.codeBlockLinesWithNumbering,
68
+ )}>
69
+ {tokens.map((line, i) => (
70
+ <Line
71
+ key={i}
72
+ line={line}
73
+ getLineProps={getLineProps}
74
+ getTokenProps={getTokenProps}
75
+ highlight={highlightLines.includes(i)}
76
+ showLineNumbers={showLineNumbers}
77
+ />
78
+ ))}
79
+ </code>
80
+ </pre>
81
+ )}
82
+ </Highlight>
83
+ <CopyButton code={code} />
84
+ </div>
85
+ </Container>
86
+ );
87
+ }
@@ -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,55 @@
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
+ import React from 'react';
8
+ import styles from './styles.module.css';
9
+ export default function CodeBlockLine({
10
+ line,
11
+ highlight,
12
+ showLineNumbers,
13
+ getLineProps,
14
+ getTokenProps,
15
+ }) {
16
+ if (line.length === 1 && line[0].content === '\n') {
17
+ line[0].content = '';
18
+ }
19
+
20
+ const lineProps = getLineProps({
21
+ line,
22
+ ...(showLineNumbers && {
23
+ className: styles.codeLine,
24
+ }),
25
+ });
26
+
27
+ if (highlight) {
28
+ lineProps.className += ' docusaurus-highlight-code-line';
29
+ }
30
+
31
+ const lineTokens = line.map((token, key) => (
32
+ <span
33
+ key={key}
34
+ {...getTokenProps({
35
+ token,
36
+ key,
37
+ })}
38
+ />
39
+ ));
40
+ return (
41
+ <span {...lineProps}>
42
+ {showLineNumbers ? (
43
+ <>
44
+ <span className={styles.codeLineNumber} />
45
+ <span className={styles.codeLineContent}>{lineTokens}</span>
46
+ </>
47
+ ) : (
48
+ <>
49
+ {lineTokens}
50
+ <br />
51
+ </>
52
+ )}
53
+ </span>
54
+ );
55
+ }
@@ -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
+ }
@@ -4,167 +4,37 @@
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, {isValidElement, useEffect, useState} from 'react';
8
- import clsx from 'clsx';
9
- import Highlight, {defaultProps} from 'prism-react-renderer';
10
- import {
11
- useThemeConfig,
12
- parseCodeBlockTitle,
13
- parseLanguage,
14
- parseLines,
15
- containsLineNumbers,
16
- ThemeClassNames,
17
- usePrismTheme,
18
- getPrismCssVariables,
19
- } from '@docusaurus/theme-common';
20
- import CopyButton from '@theme/CodeBlock/CopyButton';
21
- import styles from './styles.module.css';
22
- export default function CodeBlock({
23
- children,
24
- className: blockClassName = '',
25
- metastring,
26
- title,
27
- showLineNumbers,
28
- language: languageProp,
29
- }) {
30
- const {prism} = useThemeConfig();
31
- const [mounted, setMounted] = useState(false); // The Prism theme on SSR is always the default theme but the site theme
32
- // can be in a different mode. React hydration doesn't update DOM styles
33
- // that come from SSR. Hence force a re-render after mounting to apply the
34
- // current relevant styles. There will be a flash seen of the original
35
- // styles seen using this current approach but that's probably ok. Fixing
36
- // the flash will require changing the theming approach and is not worth it
37
- // at this point.
38
-
39
- useEffect(() => {
40
- setMounted(true);
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
-
45
- const codeBlockTitle = parseCodeBlockTitle(metastring) || title;
46
- const prismTheme = usePrismTheme();
47
- const prismCssVariables = getPrismCssVariables(prismTheme); // <pre> tags in markdown map to CodeBlocks and they may contain JSX children.
48
- // When the children is not a simple string, we just return a styled block
49
- // without actually highlighting.
7
+ import React, {isValidElement} from 'react';
8
+ import useIsBrowser from '@docusaurus/useIsBrowser';
9
+ import ElementContent from '@theme/CodeBlock/Content/Element';
10
+ import StringContent from '@theme/CodeBlock/Content/String';
11
+ /**
12
+ * Best attempt to make the children a plain string so it is copyable. If there
13
+ * are react elements, we will not be able to copy the content, and it will
14
+ * return `children` as-is; otherwise, it concatenates the string children
15
+ * together.
16
+ */
50
17
 
18
+ function maybeStringifyChildren(children) {
51
19
  if (React.Children.toArray(children).some((el) => isValidElement(el))) {
52
- return (
53
- <Highlight
54
- {...defaultProps}
55
- key={String(mounted)}
56
- theme={prismTheme}
57
- code=""
58
- language={'text'}>
59
- {({className}) => (
60
- <pre
61
- /* eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex */
62
- tabIndex={0}
63
- className={clsx(
64
- className,
65
- styles.codeBlockStandalone,
66
- 'thin-scrollbar',
67
- styles.codeBlockContainer,
68
- blockClassName,
69
- ThemeClassNames.common.codeBlock,
70
- )}
71
- style={prismCssVariables}>
72
- <code className={styles.codeBlockLines}>{children}</code>
73
- </pre>
74
- )}
75
- </Highlight>
76
- );
20
+ return children;
77
21
  } // The children is now guaranteed to be one/more plain strings
78
22
 
79
- const content = Array.isArray(children) ? children.join('') : children;
80
- const language =
81
- languageProp ?? parseLanguage(blockClassName) ?? prism.defaultLanguage;
82
- const {highlightLines, code} = parseLines(content, metastring, language);
83
- const shouldShowLineNumbers =
84
- showLineNumbers || containsLineNumbers(metastring);
85
- return (
86
- <Highlight
87
- {...defaultProps}
88
- key={String(mounted)}
89
- theme={prismTheme}
90
- code={code}
91
- language={language ?? 'text'}>
92
- {({className, tokens, getLineProps, getTokenProps}) => (
93
- <div
94
- className={clsx(
95
- styles.codeBlockContainer,
96
- blockClassName,
97
- {
98
- [`language-${language}`]:
99
- language && !blockClassName.includes(`language-${language}`),
100
- },
101
- ThemeClassNames.common.codeBlock,
102
- )}
103
- style={prismCssVariables}>
104
- {codeBlockTitle && (
105
- <div className={styles.codeBlockTitle}>{codeBlockTitle}</div>
106
- )}
107
- <div className={styles.codeBlockContent}>
108
- <pre
109
- /* eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex */
110
- tabIndex={0}
111
- className={clsx(className, styles.codeBlock, 'thin-scrollbar')}>
112
- <code
113
- className={clsx(
114
- styles.codeBlockLines,
115
- shouldShowLineNumbers && styles.codeBlockLinesWithNumbering,
116
- )}>
117
- {tokens.map((line, i) => {
118
- if (line.length === 1 && line[0].content === '\n') {
119
- line[0].content = '';
120
- }
121
-
122
- const lineProps = getLineProps({
123
- line,
124
- key: i,
125
- ...(shouldShowLineNumbers && {
126
- className: styles.codeLine,
127
- }),
128
- });
129
-
130
- if (highlightLines.includes(i)) {
131
- lineProps.className += ' docusaurus-highlight-code-line';
132
- }
133
-
134
- const lineTokens = line.map((token, key) => (
135
- <span
136
- key={key}
137
- {...getTokenProps({
138
- token,
139
- key,
140
- })}
141
- />
142
- ));
143
- return (
144
- <span key={i} {...lineProps}>
145
- {shouldShowLineNumbers ? (
146
- <>
147
- <span className={styles.codeLineNumber} />
148
- <span className={styles.codeLineContent}>
149
- {lineTokens}
150
- </span>
151
- </>
152
- ) : (
153
- <>
154
- {lineTokens}
155
- <br />
156
- </>
157
- )}
158
- </span>
159
- );
160
- })}
161
- </code>
162
- </pre>
23
+ return Array.isArray(children) ? children.join('') : children;
24
+ }
163
25
 
164
- <CopyButton code={code} />
165
- </div>
166
- </div>
167
- )}
168
- </Highlight>
26
+ export default function CodeBlock({children: rawChildren, ...props}) {
27
+ // The Prism theme on SSR is always the default theme but the site theme can
28
+ // be in a different mode. React hydration doesn't update DOM styles that come
29
+ // from SSR. Hence force a re-render after mounting to apply the current
30
+ // relevant styles.
31
+ const isBrowser = useIsBrowser();
32
+ const children = maybeStringifyChildren(rawChildren);
33
+ const CodeBlockComp =
34
+ typeof children === 'string' ? StringContent : ElementContent;
35
+ return (
36
+ <CodeBlockComp key={String(isBrowser)} {...props}>
37
+ {children}
38
+ </CodeBlockComp>
169
39
  );
170
40
  }
@@ -15,8 +15,17 @@ import clsx from 'clsx';
15
15
  import Link from '@docusaurus/Link';
16
16
  import useBaseUrl from '@docusaurus/useBaseUrl'; // TODO move to design system folder
17
17
 
18
- function BreadcrumbsItemLink({children, href}) {
18
+ function BreadcrumbsItemLink({children, href, isLast}) {
19
19
  const className = 'breadcrumbs__link';
20
+
21
+ if (isLast) {
22
+ return (
23
+ <span className={className} itemProp="name">
24
+ {children}
25
+ </span>
26
+ );
27
+ }
28
+
20
29
  return href ? (
21
30
  <Link className={className} href={href} itemProp="item">
22
31
  <span itemProp="name">{children}</span>
@@ -76,17 +85,16 @@ export default function DocBreadcrumbs() {
76
85
  itemScope
77
86
  itemType="https://schema.org/BreadcrumbList">
78
87
  {homePageRoute && <HomeBreadcrumbItem />}
79
- {breadcrumbs.map((item, idx) => (
80
- <BreadcrumbsItem
81
- key={idx}
82
- active={idx === breadcrumbs.length - 1}
83
- index={idx}>
84
- <BreadcrumbsItemLink
85
- href={idx < breadcrumbs.length - 1 ? item.href : undefined}>
86
- {item.label}
87
- </BreadcrumbsItemLink>
88
- </BreadcrumbsItem>
89
- ))}
88
+ {breadcrumbs.map((item, idx) => {
89
+ const isLast = idx === breadcrumbs.length - 1;
90
+ return (
91
+ <BreadcrumbsItem key={idx} active={isLast} index={idx}>
92
+ <BreadcrumbsItemLink href={item.href} isLast={isLast}>
93
+ {item.label}
94
+ </BreadcrumbsItemLink>
95
+ </BreadcrumbsItem>
96
+ );
97
+ })}
90
98
  </ul>
91
99
  </nav>
92
100
  );