Skip to content

Commit 8c67c2f

Browse files
authored
Merge pull request #137 from code-hike/autoimport-setting
Add autoImport setting
2 parents f94b02e + 04897c8 commit 8c67c2f

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

packages/mdx/src/plugin.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ import { transformInlineCodes } from "./plugin/inline-code"
1414
type CodeHikeConfig = {
1515
theme: any
1616
lineNumbers?: boolean
17+
autoImport?: boolean
1718
}
1819

1920
export 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(
5960
function 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

6566
function addConfig(tree: Parent, config: CodeHikeConfig) {

0 commit comments

Comments
 (0)