File tree Expand file tree Collapse file tree 8 files changed +82
-6
lines changed Expand file tree Collapse file tree 8 files changed +82
-6
lines changed Original file line number Diff line number Diff line change
1
+ import React from "react"
2
+ import {
3
+ EditorTheme ,
4
+ getColor ,
5
+ transparent ,
6
+ ColorName ,
7
+ } from "@code-hike/utils"
8
+
9
+ export function InlineCode ( {
10
+ className,
11
+ codeConfig,
12
+ children,
13
+ ...rest
14
+ } : {
15
+ className : string
16
+ children ?: React . ReactNode
17
+ codeConfig : { theme : EditorTheme }
18
+ } ) {
19
+ const { theme } = codeConfig
20
+ return (
21
+ < span
22
+ className = {
23
+ "ch-inline-code not-prose" +
24
+ ( className ? " " + className : "" )
25
+ }
26
+ { ...rest }
27
+ >
28
+ < code
29
+ style = { {
30
+ background : transparent (
31
+ getColor ( theme , ColorName . CodeBackground ) ,
32
+ 0.9
33
+ ) ,
34
+ color : getColor ( theme , ColorName . CodeForeground ) ,
35
+ } }
36
+ >
37
+ { children }
38
+ </ code >
39
+ </ span >
40
+ )
41
+ }
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import {
12
12
Annotation ,
13
13
} from "./client/annotations"
14
14
import { Preview } from "./client/preview"
15
+ import { InlineCode } from "./client/inline-code"
15
16
16
17
export const CH = {
17
18
Code,
@@ -24,4 +25,5 @@ export const CH = {
24
25
annotations : annotationsMap ,
25
26
Annotation,
26
27
Slideshow,
28
+ InlineCode,
27
29
}
Original file line number Diff line number Diff line change 17
17
height : 100% ;
18
18
}
19
19
}
20
+
21
+ .ch-inline-code > code {
22
+ padding : 0.2em 0.4em ;
23
+ margin : 0.1em -0.1em ;
24
+ border-radius : 0.25em ;
25
+ font-size : 0.9em ;
26
+ }
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import { transformSlideshows } from "./plugin/slideshow"
9
9
import { valueToEstree } from "./plugin/to-estree"
10
10
import { CH_CODE_CONFIG_VAR_NAME } from "./plugin/unist-utils"
11
11
import { transformPreviews } from "./plugin/preview"
12
+ import { transformInlineCodes } from "./plugin/inline-code"
12
13
13
14
type CodeHikeConfig = {
14
15
theme : any
@@ -36,6 +37,7 @@ export function remarkCodeHike(config: CodeHikeConfig) {
36
37
}
37
38
38
39
try {
40
+ await transformInlineCodes ( tree )
39
41
await transformPreviews ( tree )
40
42
await transformScrollycodings ( tree , config )
41
43
await transformSpotlights ( tree , config )
Original file line number Diff line number Diff line change
1
+ import {
2
+ visitAsync ,
3
+ toJSX ,
4
+ CH_CODE_CONFIG_PLACEHOLDER ,
5
+ } from "./unist-utils"
6
+ import { Node } from "unist"
7
+
8
+ export async function transformInlineCodes ( tree : Node ) {
9
+ await visitAsync (
10
+ tree ,
11
+ [ "mdxJsxFlowElement" , "mdxJsxTextElement" ] ,
12
+ async node => {
13
+ if ( node . name === "CH.InlineCode" ) {
14
+ toJSX ( node , {
15
+ props : {
16
+ codeConfig : CH_CODE_CONFIG_PLACEHOLDER ,
17
+ } ,
18
+ appendProps : true ,
19
+ } )
20
+ }
21
+ }
22
+ )
23
+ }
Original file line number Diff line number Diff line change @@ -70,6 +70,8 @@ export function toJSX(
70
70
}
71
71
if ( ! appendProps ) {
72
72
node . attributes = [ ]
73
+ } else {
74
+ node . attributes = node . attributes || [ ]
73
75
}
74
76
75
77
Object . keys ( props ) . forEach ( key => {
Original file line number Diff line number Diff line change 1
1
# Hello
2
2
3
- <CH.Preview
4
- show = " /"
5
- style = { { height: 200 }}
6
- url = " https://google.com"
7
- />
3
+ Foo bar <CH.InlineCode >Hello</CH.InlineCode > foo bar
Original file line number Diff line number Diff line change @@ -193,7 +193,10 @@ export function getColor(
193
193
}
194
194
}
195
195
196
- function transparent ( color : Color , opacity : number ) : Color {
196
+ export function transparent (
197
+ color : Color ,
198
+ opacity : number
199
+ ) : Color {
197
200
const _opacity = Math . round (
198
201
Math . min ( Math . max ( opacity || 1 , 0 ) , 1 ) * 255
199
202
)
You can’t perform that action at this time.
0 commit comments