File tree Expand file tree Collapse file tree 3 files changed +88
-8
lines changed Expand file tree Collapse file tree 3 files changed +88
-8
lines changed Original file line number Diff line number Diff line change
1
+ ` <CH.Code lineNumbers showCopyButton={false} className="foobar"> `
2
+
3
+ <CH.Code lineNumbers showCopyButton = { false } className = " foobar" >
4
+
5
+ ``` js
6
+ console .log (1 )
7
+ ```
8
+
9
+ </CH.Code >
10
+
11
+ ` <CH.Code lineNumbers={false} showCopyButton={true} className="foo"> `
12
+
13
+ <CH.Code lineNumbers = { false } showCopyButton = { true } className = " foo" >
14
+
15
+ ``` js index.js
16
+ console .log (2 )
17
+ ```
18
+
19
+ ``` python foo.py
20
+ print (3 )
21
+ ```
22
+
23
+ ---
24
+
25
+ ``` html index.html
26
+ <div >Hi</div >
27
+ ```
28
+
29
+ </CH.Code >
30
+
31
+ ` <CH.Code lineNumbers={false} showCopyButton={true} className="foo"> `
32
+
33
+ <CH.Code className = " foobarbazbarbar" style = { {border: " 2px solid red" , height: 160 }} >
34
+
35
+ ``` js index.js
36
+ console .log (2 )
37
+ console .log (2 )
38
+ console .log (2 )
39
+ console .log (2 )
40
+ console .log (2 )
41
+ console .log (2 )
42
+ console .log (2 )
43
+ console .log (2 )
44
+ console .log (2 )
45
+ console .log (2 )
46
+ ```
47
+
48
+ </CH.Code >
Original file line number Diff line number Diff line change @@ -5,8 +5,11 @@ import {
5
5
EditorProps ,
6
6
EditorStep ,
7
7
} from "../mini-editor"
8
+ import { CodeHikeConfig } from "remark/config"
8
9
9
- export function Code ( props : EditorProps ) {
10
+ export function Code (
11
+ props : EditorProps & Partial < CodeHikeConfig >
12
+ ) {
10
13
const [ step , setStep ] = React . useState ( props )
11
14
12
15
function onTabClick ( filename : string ) {
@@ -22,29 +25,57 @@ export function InnerCode({
22
25
...props
23
26
} : EditorProps & {
24
27
onTabClick ?: ( filename : string ) => void
25
- } ) {
28
+ } & Partial < CodeHikeConfig > ) {
29
+ const {
30
+ lineNumbers,
31
+ showCopyButton,
32
+ className,
33
+ style,
34
+ ...editorProps
35
+ } = props
36
+
37
+ const codeConfig = {
38
+ ...props . codeConfig ,
39
+ lineNumbers,
40
+ showCopyButton,
41
+ }
42
+
26
43
if (
27
44
! props . southPanel &&
28
45
props . files . length === 1 &&
29
46
! props . files [ 0 ] . name
30
47
) {
31
48
return (
32
- < div className = "ch-codeblock not-prose" >
49
+ < div
50
+ className = { `ch-codeblock not-prose ${
51
+ className || ""
52
+ } `}
53
+ style = { style }
54
+ >
33
55
< CodeSpring
34
56
className = "ch-code"
35
- config = { props . codeConfig }
36
- step = { props . files [ 0 ] }
57
+ config = { codeConfig }
58
+ step = { editorProps . files [ 0 ] }
37
59
/>
38
60
</ div >
39
61
)
40
62
} else {
41
63
const frameProps = {
42
- ...props ?. frameProps ,
64
+ ...editorProps ?. frameProps ,
43
65
onTabClick,
44
66
}
45
67
return (
46
- < div className = "ch-codegroup not-prose" >
47
- < EditorSpring { ...props } frameProps = { frameProps } />
68
+ < div
69
+ className = { `ch-codegroup not-prose ${
70
+ className || ""
71
+ } `}
72
+ style = { style }
73
+ >
74
+ < EditorSpring
75
+ { ...editorProps }
76
+ frameProps = { frameProps }
77
+ codeConfig = { codeConfig }
78
+ />
48
79
</ div >
49
80
)
50
81
}
Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ async function transformCode(
32
32
toJSX ( nodeInfo . node , {
33
33
name : "CH.Code" ,
34
34
props : await mapAnyCodeNode ( nodeInfo , config ) ,
35
+ appendProps : true ,
35
36
addConfigProp : true ,
36
37
} )
37
38
}
You can’t perform that action at this time.
0 commit comments