Skip to content

Commit d67feb5

Browse files
author
Jan Bílek
committed
Merge branch 'vicpon-master'
2 parents 253639d + eb58261 commit d67feb5

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

src/App.vue

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
<template>
22
<div>
3+
<div>
4+
<h3>Dynamically update code:</h3>
5+
<textarea v-model="dynamicCode"></textarea>
6+
<code-highlight>
7+
{{dynamicCode}}
8+
</code-highlight>
9+
</div>
10+
11+
<hr />
12+
313
<code-highlight>
414
let isPalindrome = (word) => {
515
let [length, result] = [word.length, true];
@@ -25,7 +35,9 @@ export default {
2535
CodeHighlight,
2636
},
2737
data() {
28-
return {};
38+
return {
39+
dynamicCode: '<div>Type here to see me change below</div>'
40+
};
2941
},
3042
};
3143
</script>
@@ -38,6 +50,10 @@ body {
3850
justify-content: center;
3951
align-items: center;
4052
}
53+
textarea {
54+
width:400px;
55+
height:200px;
56+
}
4157
@import '../themes/duotone-sea.css';
4258
@import '../themes/window.css';
4359
</style>

src/CodeHighlight.vue

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
<template>
22
<div ref="codeBlock">
3-
<pre :class="languageClass">
4-
<code>
5-
<slot></slot>
6-
</code>
7-
</pre>
3+
<pre :class="languageClass"><code><slot /></code></pre>
84
</div>
95
</template>
106

@@ -27,5 +23,11 @@ export default {
2723
mounted() {
2824
Prism.highlightAllUnder(this.$refs.codeBlock);
2925
},
26+
27+
beforeUpdate () {
28+
const newText = this.$slots.default[0].text.replace(/^[\r\n\s]*|[\r\n\s]*$/g, "");
29+
this.$el.querySelector('code').textContent = newText;
30+
Prism.highlightAllUnder(this.$refs.codeBlock);
31+
}
3032
};
3133
</script>

0 commit comments

Comments
 (0)