File tree Expand file tree Collapse file tree 1 file changed +28
-4
lines changed Expand file tree Collapse file tree 1 file changed +28
-4
lines changed Original file line number Diff line number Diff line change @@ -12,33 +12,57 @@ export type CodeBlockProps = Readonly<{
12
12
code : string ;
13
13
} > ;
14
14
15
+ const stylesForToken = ( token : Prism . Token , theme : Theme ) => {
16
+ let styles = { ...theme [ token . type ] } ;
17
+
18
+ const aliases = Array . isArray ( token . alias ) ? token . alias : [ token . alias ] ;
19
+
20
+ for ( const alias of aliases ) {
21
+ styles = { ...styles , ...theme [ alias ] } ;
22
+ }
23
+
24
+ return styles ;
25
+ } ;
26
+
15
27
const CodeBlockLine = ( {
16
28
token,
17
29
theme,
30
+ inheritedStyles,
18
31
} : {
19
32
token : string | Prism . Token ;
20
33
theme : Theme ;
34
+ inheritedStyles ?: React . CSSProperties ;
21
35
} ) => {
22
36
if ( token instanceof Prism . Token ) {
37
+ const styleForToken = {
38
+ ...inheritedStyles ,
39
+ ...stylesForToken ( token , theme ) ,
40
+ } ;
41
+
23
42
if ( token . content instanceof Prism . Token ) {
24
43
return (
25
- < span style = { theme [ token . type ] } >
44
+ < span style = { styleForToken } >
26
45
< CodeBlockLine theme = { theme } token = { token . content } />
27
46
</ span >
28
47
) ;
29
48
} else if ( typeof token . content === "string" ) {
30
- return < span style = { theme [ token . type ] } > { token . content } </ span > ;
49
+ return < span style = { styleForToken } > { token . content } </ span > ;
31
50
}
32
51
return (
33
52
< >
34
53
{ token . content . map ( ( subToken , i ) => (
35
- < CodeBlockLine key = { i } theme = { theme } token = { subToken } />
54
+ < CodeBlockLine
55
+ inheritedStyles = { styleForToken }
56
+ key = { i }
57
+ theme = { theme }
58
+ token = { subToken }
59
+ />
36
60
) ) }
37
61
</ >
38
62
) ;
39
63
}
40
64
41
- return < > { token } </ > ;
65
+ return < span style = { inheritedStyles } > { token } </ span > ;
42
66
} ;
43
67
44
68
/**
You can’t perform that action at this time.
0 commit comments