Skip to content

Commit aa041b9

Browse files
committed
chore: deprecate remarkMDC option in favor of remark-mdc
1 parent f99e6e4 commit aa041b9

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

src/runtime/stringify/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function createStringifyProcessor(options: MDCStringifyOptions = {}) {
1515
})
1616
.use(mdcRemark)
1717
.use(gfm)
18-
.use(mdc, options?.plugins?.remarkMDC?.options || {})
18+
.use(mdc, options?.plugins?.['remark-mdc']?.options || options?.plugins?.remarkMDC?.options || {})
1919
.use(stringify, {
2020
bullet: '-',
2121
emphasis: '*',

src/types/stringify.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@ export interface MDCStringifyOptions {
66
options?: YamlToStringOptions
77
}
88
plugins?: {
9-
remarkStringify?: {
9+
'remarkStringify'?: {
1010
options?: RemarkStringifyOptions
1111
}
12-
remarkMDC?: {
12+
/**
13+
* @deprecated use 'remark-mdc' instead
14+
*/
15+
'remarkMDC'?: {
16+
options?: RemarkMDCOptions
17+
}
18+
'remark-mdc'?: {
1319
options?: RemarkMDCOptions
1420
}
1521
}

test/markdown/markdown.test.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { expect, it } from 'vitest'
22
import { parseMarkdown } from '../utils/parser'
33
import { stringifyMarkdown } from '../../src/runtime/stringify'
4+
import type { MDCElement } from '@nuxtjs/mdc'
45

56
it('Element in heading', async () => {
67
const { body } = await parseMarkdown('### :hello')
@@ -14,8 +15,40 @@ it('Element in heading', async () => {
1415
children: [{ type: 'element', tag: 'hello', props: {}, children: [] }],
1516
})
1617

17-
const result = await stringifyMarkdown(body)
18+
const result = await stringifyMarkdown(body, {})
1819
expect(result).toMatchInlineSnapshot(`
1920
"### :hello\n"
2021
`)
2122
})
23+
24+
it('(autoUnwrap) component -> paragraph -> kbd', async () => {
25+
const { body } = await parseMarkdown('::tip\nYou can also use the shortcut :kbd{value="meta"} + :kbd{value="."} to redirect to the Studio route.\n::', {
26+
remark: {
27+
plugins: {
28+
'remark-mdc': {
29+
options: {
30+
autoUnwrap: true,
31+
},
32+
},
33+
},
34+
},
35+
})
36+
expect(body).toHaveProperty('type', 'root')
37+
38+
expect(body.children).toHaveLength(1)
39+
40+
expect((body.children[0] as MDCElement).children?.[0]?.type).toBe('text')
41+
42+
const result = await stringifyMarkdown(body, {}, {
43+
plugins: {
44+
'remark-mdc': {
45+
options: {
46+
autoUnwrap: true,
47+
},
48+
},
49+
},
50+
})
51+
expect(result).toMatchInlineSnapshot(`
52+
"::tip\nYou can also use the shortcut :kbd{value="meta"} + :kbd{value="."} to redirect to the Studio route.\n::\n"
53+
`)
54+
})

0 commit comments

Comments
 (0)