@@ -57,23 +57,14 @@ export interface VuePluginOptions {
57
57
[ key : string ] : string
58
58
}
59
59
/**
60
- * Exclude customBlocks for final build.
61
- * @default `['*']`
60
+ * Exclude/Include customBlocks for final build.
61
+ * @default `['! *']`
62
62
* @example
63
63
* ```js
64
- * VuePlugin({ blackListCustomBlocks : ['markdown', 'test'] })
64
+ * VuePlugin({ customBlocks : ['markdown', '! test'] })
65
65
* ```
66
66
*/
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 )
77
68
/**
78
69
* Inject CSS in JavaScript.
79
70
* @default `true`
@@ -152,24 +143,20 @@ export default function vue(opts: VuePluginOptions = {}): Plugin {
152
143
}
153
144
154
145
const shouldExtractCss = opts . css === false
155
- const blacklisted = new Set ( opts . blackListCustomBlocks || [ '*' ] )
156
- const whitelisted = new Set ( opts . whiteListCustomBlocks || [ ] )
157
146
158
- const isAllowed = ( customBlockType : string ) =>
159
- ( ! blacklisted . has ( '*' ) || ! blacklisted . has ( customBlockType ) ) &&
160
- ( whitelisted . has ( '*' ) || whitelisted . has ( customBlockType ) )
147
+ const isAllowed = createCustomBlockFilter ( opts . customBlocks )
161
148
162
149
const beforeAssemble =
163
150
opts . beforeAssemble ||
164
151
( ( d : DescriptorCompileResult ) : DescriptorCompileResult => d )
165
152
166
153
const exposeFilename =
167
154
typeof opts . exposeFilename === 'boolean' ? opts . exposeFilename : false
155
+
168
156
delete opts . beforeAssemble
169
157
delete opts . css
170
158
delete opts . exposeFilename
171
- delete opts . blackListCustomBlocks
172
- delete opts . whiteListCustomBlocks
159
+ delete opts . customBlocks
173
160
delete opts . defaultLang
174
161
delete opts . include
175
162
delete opts . exclude
@@ -382,3 +369,19 @@ export default function vue(opts: VuePluginOptions = {}): Plugin {
382
369
}
383
370
}
384
371
}
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