6
6
7
7
const Config = require ( 'markdown-it-chain' )
8
8
const highlight = require ( './lib/highlight' )
9
+ const { PLUGINS , REQUIRED_PLUGINS } = require ( './lib/constant' )
9
10
const highlightLinesPlugin = require ( './lib/highlightLines' )
10
11
const preWrapperPlugin = require ( './lib/preWrapper' )
11
12
const lineNumbersPlugin = require ( './lib/lineNumbers' )
@@ -18,7 +19,7 @@ const snippetPlugin = require('./lib/snippet')
18
19
const emojiPlugin = require ( 'markdown-it-emoji' )
19
20
const anchorPlugin = require ( 'markdown-it-anchor' )
20
21
const tocPlugin = require ( 'markdown-it-table-of-contents' )
21
- const { parseHeaders, slugify : _slugify } = require ( '@vuepress/shared-utils' )
22
+ const { parseHeaders, slugify : _slugify , logger , chalk } = require ( '@vuepress/shared-utils' )
22
23
23
24
/**
24
25
* Create markdown by config.
@@ -45,46 +46,46 @@ module.exports = ({
45
46
. highlight ( highlight )
46
47
. end ( )
47
48
48
- . plugin ( 'component' )
49
+ . plugin ( PLUGINS . COMPONENT )
49
50
. use ( componentPlugin )
50
51
. end ( )
51
52
52
- . plugin ( 'highlight-lines' )
53
+ . plugin ( PLUGINS . HIGHLIGHT_LINES )
53
54
. use ( highlightLinesPlugin )
54
55
. end ( )
55
56
56
- . plugin ( 'pre-wrapper' )
57
+ . plugin ( PLUGINS . PRE_WRAPPER )
57
58
. use ( preWrapperPlugin )
58
59
. end ( )
59
60
60
- . plugin ( 'snippet' )
61
+ . plugin ( PLUGINS . SNIPPET )
61
62
. use ( snippetPlugin )
62
63
. end ( )
63
64
64
- . plugin ( 'convert-router-link' )
65
+ . plugin ( PLUGINS . CONVERT_ROUTER_LINK )
65
66
. use ( convertRouterLinkPlugin , [ Object . assign ( {
66
67
target : '_blank' ,
67
68
rel : 'noopener noreferrer'
68
69
} , externalLinks ) ] )
69
70
. end ( )
70
71
71
- . plugin ( 'hoist-script-style' )
72
+ . plugin ( PLUGINS . HOIST_SCRIPT_STYLE )
72
73
. use ( hoistScriptStylePlugin )
73
74
. end ( )
74
75
75
- . plugin ( 'containers' )
76
+ . plugin ( PLUGINS . CONTAINERS )
76
77
. use ( containersPlugin )
77
78
. end ( )
78
79
79
- . plugin ( 'markdown-slots-containers' )
80
+ . plugin ( PLUGINS . MARKDOWN_SLOTS_CONTAINERS )
80
81
. use ( markdownSlotsContainersPlugin )
81
82
. end ( )
82
83
83
- . plugin ( 'emoji' )
84
+ . plugin ( PLUGINS . EMOJI )
84
85
. use ( emojiPlugin )
85
86
. end ( )
86
87
87
- . plugin ( 'anchor' )
88
+ . plugin ( PLUGINS . ANCHOR )
88
89
. use ( anchorPlugin , [ Object . assign ( {
89
90
slugify,
90
91
permalink : true ,
@@ -93,7 +94,7 @@ module.exports = ({
93
94
} , anchor ) ] )
94
95
. end ( )
95
96
96
- . plugin ( 'toc' )
97
+ . plugin ( PLUGINS . TOC )
97
98
. use ( tocPlugin , [ Object . assign ( {
98
99
slugify,
99
100
includeLevel : [ 2 , 3 ] ,
@@ -103,7 +104,7 @@ module.exports = ({
103
104
104
105
if ( lineNumbers ) {
105
106
config
106
- . plugin ( 'line-numbers' )
107
+ . plugin ( PLUGINS . LINE_NUMBERS )
107
108
. use ( lineNumbersPlugin )
108
109
}
109
110
@@ -143,3 +144,25 @@ function toDataBlockString (ob) {
143
144
}
144
145
return `<data>${ JSON . stringify ( ob ) } </data>`
145
146
}
147
+
148
+ function isRequiredPlugin ( plugin ) {
149
+ return REQUIRED_PLUGINS . includes ( plugin )
150
+ }
151
+
152
+ function removePlugin ( config , plugin ) {
153
+ logger . debug ( `Built-in markdown-it plugin ${ chalk . green ( plugin ) } was removed.` )
154
+ config . plugins . delete ( plugin )
155
+ }
156
+
157
+ function removeAllBuiltInPlugins ( config ) {
158
+ Object . keys ( PLUGINS ) . forEach ( key => {
159
+ if ( ! isRequiredPlugin ( PLUGINS [ key ] ) ) {
160
+ removePlugin ( config , PLUGINS [ key ] )
161
+ }
162
+ } )
163
+ }
164
+
165
+ module . exports . isRequiredPlugin = isRequiredPlugin
166
+ module . exports . removePlugin = removePlugin
167
+ module . exports . removeAllBuiltInPlugins = removeAllBuiltInPlugins
168
+ module . exports . PLUGINS = PLUGINS
0 commit comments