@@ -2,7 +2,7 @@ const { parseComponent } = require("vue-template-compiler");
22const { isCodeVueSfc } = require ( "vue-inbrowser-compiler" ) ;
33const getImports = require ( "./getImports" ) ;
44
5- const addVueLive = md => {
5+ const addVueLive = ( { noSsr } ) => md => {
66 const fence = md . renderer . rules . fence ;
77 md . renderer . rules . fence = ( ...args ) => {
88 const [ tokens , idx ] = args ;
@@ -21,6 +21,7 @@ const addVueLive = md => {
2121 const parts = parseComponent ( code ) ;
2222 return parts && parts . script ? parts . script . content : "" ;
2323 }
24+
2425 //else it could be the weird almost jsx of vue-styleguidist
2526 return code . split ( / \n [ \t ] * < / ) [ 0 ] ;
2627 } ;
@@ -40,16 +41,22 @@ const addVueLive = md => {
4041 . replace ( / \$ / g, "\\$" ) ;
4142 const editorProps = langArray . find ( l => / ^ \{ .+ \} $ / . test ( l ) ) ;
4243 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 ;
4651 } ;
4752} ;
4853
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+ } ;
5562} ;
0 commit comments