File tree Expand file tree Collapse file tree 1 file changed +4
-3
lines changed Expand file tree Collapse file tree 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"
1414type CodeHikeConfig = {
1515 theme : any
1616 lineNumbers ?: boolean
17+ autoImport ?: boolean
1718}
1819
1920export function remarkCodeHike (
2021 unsafeConfig : CodeHikeConfig
2122) {
2223 return async ( tree : Node ) => {
24+ const config = addConfigDefaults ( unsafeConfig )
2325 // TODO add opt-in config
2426 let hasCodeHikeImport = false
2527 visit ( tree , "mdxjsEsm" , ( node : any ) => {
@@ -32,11 +34,10 @@ export function remarkCodeHike(
3234 }
3335 } )
3436
35- const config = addConfigDefaults ( unsafeConfig )
3637
3738 addConfig ( tree as Parent , config )
3839
39- if ( ! hasCodeHikeImport ) {
40+ if ( config . autoImport && ! hasCodeHikeImport ) {
4041 addImportNode ( tree as Parent )
4142 }
4243
@@ -59,7 +60,7 @@ export function remarkCodeHike(
5960function addConfigDefaults (
6061 config : Partial < CodeHikeConfig > | undefined
6162) : CodeHikeConfig {
62- return { ...config , theme : config ?. theme || { } }
63+ return { ...config , theme : config ?. theme || { } , autoImport : config ?. autoImport === false ? false : true }
6364}
6465
6566function addConfig ( tree : Parent , config : CodeHikeConfig ) {
You can’t perform that action at this time.
0 commit comments