Skip to content

Commit 6b91d89

Browse files
committed
feat: allow usage of lineNumbers in editor
1 parent 7ed4d11 commit 6b91d89

File tree

6 files changed

+1956
-9895
lines changed

6 files changed

+1956
-9895
lines changed

docs/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ let value = 72
4848

4949
You can even require external libraries in your examples.
5050

51-
```vue-hybrid live
51+
```vue-hybrid live {lineNumbers:true}
5252
const _ = require("lodash")
5353
const anu = [2, 5, 7]
5454
const newArray = []

layout.vue

+5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
.preview-code .editor .prism-editor-wrapper {
2626
height: 100%;
2727
}
28+
29+
.preview-code .editor .prism-editor-wrapper > .prism-editor__line-numbers {
30+
position: absolute;
31+
}
32+
2833
.preview-code .editor pre {
2934
margin: 0;
3035
box-sizing: border-box;

markDownPlugin.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const addVueLive = md => {
1010
const lang = token.info.trim();
1111

1212
// if it does not ends with live just use default fence
13-
if (!/ live$/.test(lang)) {
13+
if (!/ live$/.test(lang) && !/ live /.test(lang)) {
1414
return fence(...args);
1515
}
1616

@@ -34,11 +34,15 @@ const addVueLive = md => {
3434
const requires = getImports(scr).map(mod => `'${mod}': require('${mod}')`);
3535
const langArray = lang.split(" ");
3636
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
37+
const codeClean = md.utils
3938
.escapeHtml(code)
4039
.replace(/\`/g, "\\`")
41-
.replace(/\$/g, "\\$")}\`" :requires="{${requires.join(",")}}"/>`;
40+
.replace(/\$/g, "\\$");
41+
const editorProps = langArray.find(l => /^\{.+\}$/.test(l));
42+
const jsx = langArray.length > 2 && langArray[1] === "jsx" ? "jsx " : ""; // to enable jsx, we want ```vue jsx live or ```jsx jsx live
43+
return `<vue-live ${jsx}:layoutProps="{lang:'${langClean}'}" :code="\`${codeClean}\`" :requires="{${requires.join(
44+
","
45+
)}}"${editorProps ? ` :editorProps="${editorProps}"` : ""} />`;
4246
};
4347
};
4448

0 commit comments

Comments
 (0)