Skip to content

Commit 5bfd0ce

Browse files
committed
feat: enable jsx render function in examples
1 parent 55c1cff commit 5bfd0ce

File tree

3 files changed

+7773
-3
lines changed

3 files changed

+7773
-3
lines changed

docs/README.md

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Vuepress-live allows you to make your examples more interactive automatically. F
66

77
Writing this in your markdown...
88

9-
````
9+
````md
1010
```vue live
1111
<button>example</button>
1212
```
@@ -57,3 +57,46 @@ _.each(anu, a => {
5757
value: {{ newArray.join(", ") }}
5858
</div>
5959
```
60+
61+
## Enable jsx with the jsx flag
62+
63+
If your examples are jsx vue components, use an extra jsx flag
64+
65+
````md
66+
```jsx jsx live
67+
export default {
68+
render(){
69+
return <vue-slider
70+
value={37}
71+
/>
72+
}
73+
}
74+
```
75+
````
76+
77+
> **NOTE**: The jsx flag should always be second after the language. If you use just `jsx live` as a flag it will use the standard vue parser.
78+
> JSX syntax highlighting in markdown is better than vue. You can still use jsx with your normal examples.
79+
80+
Without the second jsx flag, vue-live would pick up on the beginnig of the jsx expression and stop parsing there.
81+
The script would be incomplete.
82+
83+
```jsx jsx live
84+
export default {
85+
data(){
86+
return {
87+
value: 37
88+
}
89+
},
90+
render(){
91+
return (
92+
<div>
93+
<vue-slider
94+
style={{margin: "20px 0"}}
95+
value={this.value}
96+
order={false}
97+
/>
98+
</div>
99+
)
100+
}
101+
}
102+
```

markDownPlugin.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ const addVueLive = md => {
3232
// add this as a prop
3333
const scr = getScript(code);
3434
const requires = getImports(scr).map(mod => `'${mod}': require('${mod}')`);
35-
const langClean = lang.split(" ")[0];
36-
return `<vue-live :layoutProps="{lang:'${langClean}'}" :code="\`${md.utils
35+
const langArray = lang.split(" ");
36+
const langClean = langArray[0];
37+
const jsx = langArray.length > 2 && langArray[1] === "jsx" ? "jsx " : ""; // to enable jsx, we want ```vue jsx live or ```jsx jsx live
38+
return `<vue-live ${jsx}:layoutProps="{lang:'${langClean}'}" :code="\`${md.utils
3739
.escapeHtml(code)
3840
.replace(/\`/g, "\\`")
3941
.replace(/\$/g, "\\$")}\`" :requires="{${requires.join(",")}}"/>`;

0 commit comments

Comments
 (0)