File tree Expand file tree Collapse file tree 5 files changed +3
-36
lines changed
docusaurus-theme-classic/src/theme/CodeBlock
docusaurus-theme-common/src Expand file tree Collapse file tree 5 files changed +3
-36
lines changed Original file line number Diff line number Diff line change 7
7
8
8
import React , { type ComponentProps } from 'react' ;
9
9
import clsx from 'clsx' ;
10
- import { ThemeClassNames , usePrismTheme } from '@docusaurus/theme-common' ;
11
- import { getPrismCssVariables } from '@docusaurus/theme-common/internal' ;
10
+ import { ThemeClassNames } from '@docusaurus/theme-common' ;
12
11
import styles from './styles.module.css' ;
13
12
14
13
export default function CodeBlockContainer < T extends 'div' | 'pre' > ( {
15
14
as : As ,
16
15
...props
17
16
} : { as : T } & ComponentProps < T > ) : JSX . Element {
18
- const prismTheme = usePrismTheme ( ) ;
19
- const prismCssVariables = getPrismCssVariables ( prismTheme ) ;
20
17
return (
21
18
< As
22
19
// Polymorphic components are hard to type, without `oneOf` generics
23
20
{ ...( props as any ) }
24
- style = { prismCssVariables }
25
21
className = { clsx (
26
22
props . className ,
27
23
styles . codeBlockContainer ,
Original file line number Diff line number Diff line change 6
6
*/
7
7
8
8
import React , { isValidElement , type ReactNode } from 'react' ;
9
- import useIsBrowser from '@docusaurus/useIsBrowser' ;
10
9
import ElementContent from '@theme/CodeBlock/Content/Element' ;
11
10
import StringContent from '@theme/CodeBlock/Content/String' ;
12
11
import type { Props } from '@theme/CodeBlock' ;
@@ -29,17 +28,8 @@ export default function CodeBlock({
29
28
children : rawChildren ,
30
29
...props
31
30
} : 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
31
const children = maybeStringifyChildren ( rawChildren ) ;
38
32
const CodeBlockComp =
39
33
typeof children === 'string' ? StringContent : ElementContent ;
40
- return (
41
- < CodeBlockComp key = { String ( isBrowser ) } { ...props } >
42
- { children as string }
43
- </ CodeBlockComp >
44
- ) ;
34
+ return < CodeBlockComp { ...props } > { children as string } </ CodeBlockComp > ;
45
35
}
Original file line number Diff line number Diff line change @@ -118,5 +118,4 @@ export {useLockBodyScroll} from './hooks/useLockBodyScroll';
118
118
export { useSearchPage } from './hooks/useSearchPage' ;
119
119
export { useCodeWordWrap } from './hooks/useCodeWordWrap' ;
120
120
export { useSkipToContent } from './hooks/useSkipToContent' ;
121
- export { getPrismCssVariables } from './utils/codeBlockUtils' ;
122
121
export { useBackToTopButton } from './hooks/useBackToTopButton' ;
Original file line number Diff line number Diff line change 5
5
* LICENSE file in the root directory of this source tree.
6
6
*/
7
7
8
- import type { CSSProperties } from 'react' ;
9
8
import rangeParser from 'parse-numeric-range' ;
10
- import type { PrismTheme } from 'prism-react-renderer' ;
11
9
12
10
const codeBlockTitleRegex = / t i t l e = (?< quote > [ " ' ] ) (?< title > .* ?) \1/ ;
13
11
const metastringLinesRangeRegex = / \{ (?< range > [ \d , - ] + ) \} / ;
@@ -233,19 +231,3 @@ export function parseLines(
233
231
} ) ;
234
232
return { lineClassNames, code} ;
235
233
}
236
-
237
- export function getPrismCssVariables ( prismTheme : PrismTheme ) : CSSProperties {
238
- const mapping : { [ name : keyof PrismTheme [ 'plain' ] ] : string } = {
239
- color : '--prism-color' ,
240
- backgroundColor : '--prism-background-color' ,
241
- } ;
242
-
243
- const properties : { [ key : string ] : string } = { } ;
244
- Object . entries ( prismTheme . plain ) . forEach ( ( [ key , value ] ) => {
245
- const varName = mapping [ key ] ;
246
- if ( varName && typeof value === 'string' ) {
247
- properties [ varName ] = value ;
248
- }
249
- } ) ;
250
- return properties ;
251
- }
Original file line number Diff line number Diff line change @@ -59,7 +59,7 @@ export type AnnouncementBarConfig = {
59
59
60
60
export type PrismConfig = {
61
61
theme : PrismTheme ;
62
- darkTheme ? : PrismTheme ;
62
+ darkTheme : PrismTheme ;
63
63
defaultLanguage ?: string ;
64
64
additionalLanguages : string [ ] ;
65
65
magicComments : MagicCommentConfig [ ] ;
You can’t perform that action at this time.
0 commit comments