File tree 1 file changed +4
-3
lines changed
1 file changed +4
-3
lines changed Original file line number Diff line number Diff line change @@ -14,12 +14,14 @@ import { transformInlineCodes } from "./plugin/inline-code"
14
14
type CodeHikeConfig = {
15
15
theme : any
16
16
lineNumbers ?: boolean
17
+ autoImport ?: boolean
17
18
}
18
19
19
20
export function remarkCodeHike (
20
21
unsafeConfig : CodeHikeConfig
21
22
) {
22
23
return async ( tree : Node ) => {
24
+ const config = addConfigDefaults ( unsafeConfig )
23
25
// TODO add opt-in config
24
26
let hasCodeHikeImport = false
25
27
visit ( tree , "mdxjsEsm" , ( node : any ) => {
@@ -32,11 +34,10 @@ export function remarkCodeHike(
32
34
}
33
35
} )
34
36
35
- const config = addConfigDefaults ( unsafeConfig )
36
37
37
38
addConfig ( tree as Parent , config )
38
39
39
- if ( ! hasCodeHikeImport ) {
40
+ if ( config . autoImport && ! hasCodeHikeImport ) {
40
41
addImportNode ( tree as Parent )
41
42
}
42
43
@@ -59,7 +60,7 @@ export function remarkCodeHike(
59
60
function addConfigDefaults (
60
61
config : Partial < CodeHikeConfig > | undefined
61
62
) : CodeHikeConfig {
62
- return { ...config , theme : config ?. theme || { } }
63
+ return { ...config , theme : config ?. theme || { } , autoImport : config ?. autoImport === false ? false : true }
63
64
}
64
65
65
66
function addConfig ( tree : Parent , config : CodeHikeConfig ) {
You can’t perform that action at this time.
0 commit comments