@@ -2,7 +2,7 @@ const { parseComponent } = require("vue-template-compiler");
2
2
const { isCodeVueSfc } = require ( "vue-inbrowser-compiler" ) ;
3
3
const getImports = require ( "./getImports" ) ;
4
4
5
- const addVueLive = md => {
5
+ const addVueLive = ( { noSsr } ) => md => {
6
6
const fence = md . renderer . rules . fence ;
7
7
md . renderer . rules . fence = ( ...args ) => {
8
8
const [ tokens , idx ] = args ;
@@ -21,6 +21,7 @@ const addVueLive = md => {
21
21
const parts = parseComponent ( code ) ;
22
22
return parts && parts . script ? parts . script . content : "" ;
23
23
}
24
+
24
25
//else it could be the weird almost jsx of vue-styleguidist
25
26
return code . split ( / \n [ \t ] * < / ) [ 0 ] ;
26
27
} ;
@@ -40,16 +41,22 @@ const addVueLive = md => {
40
41
. replace ( / \$ / g, "\\$" ) ;
41
42
const editorProps = langArray . find ( l => / ^ \{ .+ \} $ / . test ( l ) ) ;
42
43
const jsx = langArray . length > 2 && langArray [ 1 ] === "jsx" ? "jsx " : "" ; // to enable jsx, we want ```vue jsx live or ```jsx jsx live
43
- return `<no-ssr><vue-live ${ jsx } :layoutProps="{lang:'${ langClean } '}" :code="\`${ codeClean } \`" :requires="{${ requires . join (
44
- ","
45
- ) } }"${ editorProps ? ` :editorProps="${ editorProps } "` : "" } /></no-ssr>`;
44
+ const markdownGenerated = `<vue-live ${ jsx }
45
+ :layoutProps="{lang:'${ langClean } '}"
46
+ :code="\`${ codeClean } \`"
47
+ :requires="{${ requires . join ( "," ) } }"
48
+ ${ editorProps ? ` :editorProps="${ editorProps } "` : "" }
49
+ />` ;
50
+ return noSsr ? `<no-ssr>${ markdownGenerated } </no-ssr>` : markdownGenerated ;
46
51
} ;
47
52
} ;
48
53
49
- module . exports = function markDownPlugin ( config ) {
50
- config . plugins . delete ( "snippet" ) ;
51
- config
52
- . plugin ( "vue-live" )
53
- . use ( addVueLive )
54
- . end ( ) ;
54
+ module . exports = function ( options ) {
55
+ return function markDownPlugin ( config ) {
56
+ config . plugins . delete ( "snippet" ) ;
57
+ config
58
+ . plugin ( "vue-live" )
59
+ . use ( addVueLive ( options ) )
60
+ . end ( ) ;
61
+ } ;
55
62
} ;
0 commit comments