Skip to content

Commit 8588dfb

Browse files
committed
More robust config
1 parent f7c6ae0 commit 8588dfb

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

packages/mdx/src/plugin.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ type CodeHikeConfig = {
1616
lineNumbers?: boolean
1717
}
1818

19-
export function remarkCodeHike(config: CodeHikeConfig) {
19+
export function remarkCodeHike(
20+
unsafeConfig: CodeHikeConfig
21+
) {
2022
return async (tree: Node) => {
2123
// TODO add opt-in config
2224
let hasCodeHikeImport = false
@@ -30,6 +32,8 @@ export function remarkCodeHike(config: CodeHikeConfig) {
3032
}
3133
})
3234

35+
const config = addConfigDefaults(unsafeConfig)
36+
3337
addConfig(tree as Parent, config)
3438

3539
if (!hasCodeHikeImport) {
@@ -52,6 +56,12 @@ export function remarkCodeHike(config: CodeHikeConfig) {
5256
}
5357
}
5458

59+
function addConfigDefaults(
60+
config: Partial<CodeHikeConfig> | undefined
61+
): CodeHikeConfig {
62+
return { ...config, theme: config?.theme || {} }
63+
}
64+
5565
function addConfig(tree: Parent, config: CodeHikeConfig) {
5666
tree.children.unshift({
5767
type: "mdxjsEsm",

0 commit comments

Comments
 (0)