@@ -57,23 +57,14 @@ export interface VuePluginOptions {
5757 [ key : string ] : string
5858 }
5959 /**
60- * Exclude customBlocks for final build.
61- * @default `['*']`
60+ * Exclude/Include customBlocks for final build.
61+ * @default `['! *']`
6262 * @example
6363 * ```js
64- * VuePlugin({ blackListCustomBlocks : ['markdown', 'test'] })
64+ * VuePlugin({ customBlocks : ['markdown', '! test'] })
6565 * ```
6666 */
67- blackListCustomBlocks ?: string [ ]
68- /**
69- * Include customBlocks for final build.
70- * @default `[]`
71- * @example
72- * ```js
73- * VuePlugin({ blackListCustomBlocks: ['markdown', 'test'] })
74- * ```
75- */
76- whiteListCustomBlocks ?: string [ ]
67+ customBlocks ?: string [ ] | ( ( ) => boolean )
7768 /**
7869 * Inject CSS in JavaScript.
7970 * @default `true`
@@ -152,24 +143,20 @@ export default function vue(opts: VuePluginOptions = {}): Plugin {
152143 }
153144
154145 const shouldExtractCss = opts . css === false
155- const blacklisted = new Set ( opts . blackListCustomBlocks || [ '*' ] )
156- const whitelisted = new Set ( opts . whiteListCustomBlocks || [ ] )
157146
158- const isAllowed = ( customBlockType : string ) =>
159- ( ! blacklisted . has ( '*' ) || ! blacklisted . has ( customBlockType ) ) &&
160- ( whitelisted . has ( '*' ) || whitelisted . has ( customBlockType ) )
147+ const isAllowed = createCustomBlockFilter ( opts . customBlocks )
161148
162149 const beforeAssemble =
163150 opts . beforeAssemble ||
164151 ( ( d : DescriptorCompileResult ) : DescriptorCompileResult => d )
165152
166153 const exposeFilename =
167154 typeof opts . exposeFilename === 'boolean' ? opts . exposeFilename : false
155+
168156 delete opts . beforeAssemble
169157 delete opts . css
170158 delete opts . exposeFilename
171- delete opts . blackListCustomBlocks
172- delete opts . whiteListCustomBlocks
159+ delete opts . customBlocks
173160 delete opts . defaultLang
174161 delete opts . include
175162 delete opts . exclude
@@ -382,3 +369,19 @@ export default function vue(opts: VuePluginOptions = {}): Plugin {
382369 }
383370 }
384371}
372+
373+ function createCustomBlockFilter (
374+ customBlocks ?: string [ ] | ( ( tag : string ) => boolean )
375+ ) : ( tag : string ) => boolean {
376+ if ( typeof customBlocks === 'function' ) return customBlocks
377+ if ( ! Array . isArray ( customBlocks ) ) return ( ) => false
378+
379+ const allowed = new Set ( customBlocks . filter ( tag => ! tag . startsWith ( '!' ) ) )
380+ const notAllowed = new Set (
381+ customBlocks . filter ( tag => tag . startsWith ( '!' ) ) . map ( tag => tag . substr ( 1 ) )
382+ )
383+
384+ return tag =>
385+ ( allowed . has ( '*' ) || allowed . has ( tag ) ) &&
386+ ! ( notAllowed . has ( '*' ) || notAllowed . has ( tag ) )
387+ }
0 commit comments