66
77const Config = require ( 'markdown-it-chain' )
88const highlight = require ( './lib/highlight' )
9+ const { PLUGINS , REQUIRED_PLUGINS } = require ( './lib/constant' )
910const highlightLinesPlugin = require ( './lib/highlightLines' )
1011const preWrapperPlugin = require ( './lib/preWrapper' )
1112const lineNumbersPlugin = require ( './lib/lineNumbers' )
@@ -18,7 +19,7 @@ const snippetPlugin = require('./lib/snippet')
1819const emojiPlugin = require ( 'markdown-it-emoji' )
1920const anchorPlugin = require ( 'markdown-it-anchor' )
2021const 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' )
2223
2324/**
2425 * Create markdown by config.
@@ -45,46 +46,46 @@ module.exports = ({
4546 . highlight ( highlight )
4647 . end ( )
4748
48- . plugin ( 'component' )
49+ . plugin ( PLUGINS . COMPONENT )
4950 . use ( componentPlugin )
5051 . end ( )
5152
52- . plugin ( 'highlight-lines' )
53+ . plugin ( PLUGINS . HIGHLIGHT_LINES )
5354 . use ( highlightLinesPlugin )
5455 . end ( )
5556
56- . plugin ( 'pre-wrapper' )
57+ . plugin ( PLUGINS . PRE_WRAPPER )
5758 . use ( preWrapperPlugin )
5859 . end ( )
5960
60- . plugin ( 'snippet' )
61+ . plugin ( PLUGINS . SNIPPET )
6162 . use ( snippetPlugin )
6263 . end ( )
6364
64- . plugin ( 'convert-router-link' )
65+ . plugin ( PLUGINS . CONVERT_ROUTER_LINK )
6566 . use ( convertRouterLinkPlugin , [ Object . assign ( {
6667 target : '_blank' ,
6768 rel : 'noopener noreferrer'
6869 } , externalLinks ) ] )
6970 . end ( )
7071
71- . plugin ( 'hoist-script-style' )
72+ . plugin ( PLUGINS . HOIST_SCRIPT_STYLE )
7273 . use ( hoistScriptStylePlugin )
7374 . end ( )
7475
75- . plugin ( 'containers' )
76+ . plugin ( PLUGINS . CONTAINERS )
7677 . use ( containersPlugin )
7778 . end ( )
7879
79- . plugin ( 'markdown-slots-containers' )
80+ . plugin ( PLUGINS . MARKDOWN_SLOTS_CONTAINERS )
8081 . use ( markdownSlotsContainersPlugin )
8182 . end ( )
8283
83- . plugin ( 'emoji' )
84+ . plugin ( PLUGINS . EMOJI )
8485 . use ( emojiPlugin )
8586 . end ( )
8687
87- . plugin ( 'anchor' )
88+ . plugin ( PLUGINS . ANCHOR )
8889 . use ( anchorPlugin , [ Object . assign ( {
8990 slugify,
9091 permalink : true ,
@@ -93,7 +94,7 @@ module.exports = ({
9394 } , anchor ) ] )
9495 . end ( )
9596
96- . plugin ( 'toc' )
97+ . plugin ( PLUGINS . TOC )
9798 . use ( tocPlugin , [ Object . assign ( {
9899 slugify,
99100 includeLevel : [ 2 , 3 ] ,
@@ -103,7 +104,7 @@ module.exports = ({
103104
104105 if ( lineNumbers ) {
105106 config
106- . plugin ( 'line-numbers' )
107+ . plugin ( PLUGINS . LINE_NUMBERS )
107108 . use ( lineNumbersPlugin )
108109 }
109110
@@ -143,3 +144,25 @@ function toDataBlockString (ob) {
143144 }
144145 return `<data>${ JSON . stringify ( ob ) } </data>`
145146}
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