Skip to content

Commit 8ee7ae4

Browse files
committed
fix: use option for noSsr
1 parent 40991c7 commit 8ee7ae4

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ module.exports = (options, app, plugin) => {
77
name: "vuepress-plugin-live",
88
chainWebpack: chainWebpack(options),
99
enhanceAppFiles,
10-
chainMarkdown
10+
chainMarkdown: chainMarkdown(options),
1111
};
1212
};

markDownPlugin.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const { parseComponent } = require("vue-template-compiler");
22
const { isCodeVueSfc } = require("vue-inbrowser-compiler");
33
const 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

Comments
 (0)