Skip to content

Commit 385577c

Browse files
pengzhanboMister-Hopemeteorlxy
committedMay 27, 2024·
refactor(markdown): remove codePlugin and add vPrePlugin (close #1550) (#1556)
BREAKING CHANGE: `markdown.code` option is remove. Please use `@vuepress/plugin-shiki` and `@vuepress/plugin-prismjs` instead. -------------- Co-authored-by: 张怀文 <mister-hope@outlook.com> Co-authored-by: meteorlxy <meteor.lxy@foxmail.com>
1 parent 4df59d4 commit 385577c

17 files changed

+371
-1185
lines changed
 

‎packages/markdown/src/markdown.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { slugify as defaultSlugify } from '@mdit-vue/shared'
2+
import { logger } from '@vuepress/utils'
23
import MarkdownIt from 'markdown-it'
34
import {
45
anchorPlugin,
56
assetsPlugin,
6-
codePlugin,
77
componentPlugin,
88
emojiPlugin,
99
frontmatterPlugin,
@@ -13,18 +13,19 @@ import {
1313
sfcPlugin,
1414
titlePlugin,
1515
tocPlugin,
16+
vPrePlugin,
1617
} from './plugins.js'
1718
import type {
1819
AnchorPluginOptions,
1920
AssetsPluginOptions,
20-
CodePluginOptions,
2121
EmojiPluginOptions,
2222
FrontmatterPluginOptions,
2323
HeadersPluginOptions,
2424
ImportCodePluginOptions,
2525
LinksPluginOptions,
2626
SfcPluginOptions,
2727
TocPluginOptions,
28+
VPrePluginOptions,
2829
} from './plugins.js'
2930
import type { Markdown, MarkdownOptions } from './types.js'
3031

@@ -35,6 +36,7 @@ export const createMarkdown = ({
3536
anchor,
3637
assets,
3738
code,
39+
vPre,
3840
component,
3941
emoji,
4042
frontmatter,
@@ -82,8 +84,10 @@ export const createMarkdown = ({
8284
}
8385

8486
// process code fence
85-
if (code !== false) {
86-
md.use<CodePluginOptions>(codePlugin, code)
87+
if (code) {
88+
logger.warn(
89+
`\`markdown.code\` option has been removed, please use '@vuepress/plugin-shiki' or '@vuepress/plugin-prismjs' instead.\n See https://v2.vuepress.vuejs.org/reference/config.html#markdown-code`,
90+
)
8791
}
8892

8993
// treat unknown html tags as components
@@ -146,5 +150,10 @@ export const createMarkdown = ({
146150
md.use(titlePlugin)
147151
}
148152

153+
// add v-pre to `<pre>` and `<code>`
154+
if (vPre !== false) {
155+
md.use<VPrePluginOptions>(vPrePlugin, vPre)
156+
}
157+
149158
return md
150159
}

‎packages/markdown/src/plugins.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ export {
2222
assetsPlugin,
2323
type AssetsPluginOptions,
2424
} from './plugins/assetsPlugin/assetsPlugin.js'
25-
export {
26-
codePlugin,
27-
type CodePluginOptions,
28-
} from './plugins/codePlugin/codePlugin.js'
2925
export { emojiPlugin, type EmojiPluginOptions } from './plugins/emojiPlugin.js'
3026
export {
3127
importCodePlugin,
@@ -35,3 +31,7 @@ export {
3531
linksPlugin,
3632
type LinksPluginOptions,
3733
} from './plugins/linksPlugin/linksPlugin.js'
34+
export {
35+
vPrePlugin,
36+
type VPrePluginOptions,
37+
} from './plugins/vPrePlugin/vPrePlugin.js'

‎packages/markdown/src/plugins/codePlugin/codePlugin.ts

-151
This file was deleted.

‎packages/markdown/src/plugins/codePlugin/languages.ts

-105
This file was deleted.

‎packages/markdown/src/plugins/codePlugin/resolveAttr.ts

-12
This file was deleted.

‎packages/markdown/src/plugins/codePlugin/resolveHighlightLines.ts

-34
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.