1
1
const mdContainer = require ( 'markdown-it-container' ) ;
2
2
3
- module . exports = md => {
4
- md . use ( mdContainer , 'demo' , {
5
- validate ( params ) {
6
- return params . trim ( ) . match ( / ^ d e m o \s * ( .* ) $ / ) ;
7
- } ,
8
- render ( tokens , idx ) {
9
- const m = tokens [ idx ] . info . trim ( ) . match ( / ^ d e m o \s * ( .* ) $ / ) ;
10
- if ( tokens [ idx ] . nesting === 1 ) {
11
- const description = m && m . length > 1 ? m [ 1 ] : '' ;
12
- const content = tokens [ idx + 1 ] . type === 'fence' ? tokens [ idx + 1 ] . content : '' ;
13
- return `<demo-block>
14
- <!--pre-render-demo:${ content } :pre-render-demo-->
15
- ${ description ? `<div slot="description">${ md . render ( description ) . html } </div>` : '' }
16
- <template slot="source">
17
- ` ;
3
+ module . exports = options => {
4
+ const {
5
+ component = 'demo-block'
6
+ } = options ;
7
+ const componentName = component
8
+ . replace ( / ^ \S / , s => s . toLowerCase ( ) )
9
+ . replace ( / ( [ A - Z ] ) / g, "-$1" ) . toLowerCase ( ) ;
10
+ return md => {
11
+ md . use ( mdContainer , 'demo' , {
12
+ validate ( params ) {
13
+ return params . trim ( ) . match ( / ^ d e m o \s * ( .* ) $ / ) ;
14
+ } ,
15
+ render ( tokens , idx ) {
16
+ const m = tokens [ idx ] . info . trim ( ) . match ( / ^ d e m o \s * ( .* ) $ / ) ;
17
+ if ( tokens [ idx ] . nesting === 1 ) {
18
+ const description = m && m . length > 1 ? m [ 1 ] : '' ;
19
+ const content = tokens [ idx + 1 ] . type === 'fence' ? tokens [ idx + 1 ] . content : '' ;
20
+ return `<${ componentName } >
21
+ <template slot="demo"><!--pre-render-demo:${ content } :pre-render-demo--></template>
22
+ ${ description ? `<div slot="description">${ md . render ( description ) . html } </div>` : '' }
23
+ <template slot="source">
24
+ ` ;
25
+ }
26
+ return `</template></${ componentName } >` ;
18
27
}
19
- return '</template></demo-block>' ;
20
- }
21
- } ) ;
22
- } ;
28
+ } ) ;
29
+ } ;
30
+ }
0 commit comments