mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-23 00:27:49 +08:00
8c6751f0c6
* chore: add precommit hook for eslint fixes, fix linting issues * chore: add eslint import sort plugin
74 lines
1.1 KiB
Vue
74 lines
1.1 KiB
Vue
<template>
|
|
<div v-if="html" v-html="html" />
|
|
<pre v-else><code>{{ code }}</code></pre>
|
|
</template>
|
|
|
|
<script>
|
|
// this import is a bugfix
|
|
// otherwise the `onig.wasm` file is missing in the dist folder
|
|
import 'shiki/dist/onig.wasm?url'
|
|
|
|
import Worker from './shiki.worker?worker'
|
|
|
|
export default {
|
|
props: {
|
|
code: {
|
|
default: '',
|
|
type: String,
|
|
},
|
|
|
|
language: {
|
|
default: 'js',
|
|
type: String,
|
|
},
|
|
},
|
|
|
|
data() {
|
|
return {
|
|
worker: new Worker(),
|
|
html: null,
|
|
highlighter: window?.highlighter,
|
|
}
|
|
},
|
|
|
|
watch: {
|
|
code: {
|
|
immediate: true,
|
|
handler() {
|
|
this.render()
|
|
},
|
|
},
|
|
|
|
highlighter: {
|
|
immediate: true,
|
|
handler() {
|
|
this.render()
|
|
},
|
|
},
|
|
},
|
|
|
|
methods: {
|
|
render() {
|
|
this.worker.postMessage({
|
|
code: this.code,
|
|
language: this.language,
|
|
})
|
|
},
|
|
},
|
|
|
|
created() {
|
|
this.worker.addEventListener('message', event => {
|
|
const { html } = event.data
|
|
|
|
this.html = html
|
|
})
|
|
},
|
|
}
|
|
</script>
|
|
|
|
<style>
|
|
.shiki {
|
|
background-color: transparent !important;
|
|
}
|
|
</style>
|