Former-commit-id: 7932c8c5dd5ed9356f6197b6b02ef689b692dc8e Former-commit-id: 2ac198cd44f684e8e6028f82ce70cc8371123178 Former-commit-id: f68e338389ad4432272497b7a2e48b10ce7f9719
37 lines
642 B
Vue
37 lines
642 B
Vue
<template>
|
|
<pre v-html="highlightHTML"></pre>
|
|
</template>
|
|
|
|
<script>
|
|
// https://highlightjs.org/usage/
|
|
// http://highlightjs.readthedocs.io/en/latest/api.html#configure-options
|
|
import highlight from 'highlight.js'
|
|
export default {
|
|
props: {
|
|
code: {
|
|
type: String,
|
|
required: false,
|
|
default: `console.log('you lost code prop')`
|
|
}
|
|
},
|
|
data () {
|
|
return {
|
|
highlightHTML: ''
|
|
}
|
|
},
|
|
mounted () {
|
|
this.highlight()
|
|
},
|
|
watch: {
|
|
code () {
|
|
this.highlight()
|
|
}
|
|
},
|
|
methods: {
|
|
highlight () {
|
|
this.highlightHTML = highlight.highlightAuto(this.code).value
|
|
}
|
|
}
|
|
}
|
|
</script>
|