Skip to content

Commit cc6045a

Browse files
committed
fix(node-env): dynamic import module options
1 parent e7387d8 commit cc6045a

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

src/runtime/parser/index.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,17 @@ import { rehypeShiki } from './shiki'
1111
import { generateToc } from './toc'
1212
import { nodeTextContent } from '../utils/node'
1313

14+
let moduleOptions: any
1415
export const parseMarkdown = async (md: string, opts: MDCParseOptions = {}) => {
15-
const options = defu(opts, defaults)
16+
if (!moduleOptions) {
17+
// @ts-ignore
18+
moduleOptions = await import('#mdc-imports' /* @vite-ignore */).catch(() => ({}))
19+
}
20+
const options = defu(opts, {
21+
remark: { plugins: moduleOptions.remarkPlugins },
22+
rehype: { plugins: moduleOptions.rehypePlugins },
23+
highlight: moduleOptions.highlight,
24+
}, defaults)
1625

1726
// Extract front matter data
1827
const { content, data: frontmatter } = await parseFrontMatter(md)
@@ -29,7 +38,7 @@ export const parseMarkdown = async (md: string, opts: MDCParseOptions = {}) => {
2938
await useProcessorPlugins(processor as any, options.remark?.plugins)
3039

3140
// Turns markdown into HTML to support rehype
32-
processor.use(remark2rehype as any, options.rehype?.options)
41+
processor.use(remark2rehype as any, (options.rehype as any)?.options)
3342

3443
if (options.highlight) {
3544
processor.use(rehypeShiki, options.highlight)

src/runtime/parser/options.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import rehypeSortAttributeValues from 'rehype-sort-attribute-values'
66
import rehypeSortAttributes from 'rehype-sort-attributes'
77
import rehypeRaw from 'rehype-raw'
88
import type { MDCParseOptions } from '../types'
9-
// @ts-ignore
10-
import { remarkPlugins, rehypePlugins, highlight } from '#mdc-imports'
119

1210
export const defaults: MDCParseOptions = {
1311
remark: {
@@ -17,8 +15,7 @@ export const defaults: MDCParseOptions = {
1715
},
1816
'remark-gfm': {
1917
instance: remarkGFM
20-
},
21-
...remarkPlugins
18+
}
2219
}
2320
},
2421
rehype: {
@@ -42,11 +39,10 @@ export const defaults: MDCParseOptions = {
4239
options: {
4340
passThrough: ['element']
4441
}
45-
},
46-
...rehypePlugins
42+
}
4743
}
4844
},
49-
highlight,
45+
highlight: false,
5046
toc: {
5147
searchDepth: 2,
5248
depth: 2

0 commit comments

Comments
 (0)