1
0
Fork 0
mirror of https://gitlab.com/bramw/baserow.git synced 2025-04-12 16:28:06 +00:00
bramw_baserow/web-frontend/modules/core/components/MarkdownIt.vue

50 lines
1,017 B
Vue

<template>
<!-- eslint-disable-next-line vue/no-v-html vue/no-v-text-v-html-on-component -->
<component :is="tag" class="markdown" v-html="htmlContent" />
</template>
<script>
export default {
name: 'MarkdownIt',
props: {
content: {
required: true,
type: String,
},
tag: {
required: false,
type: String,
default: 'div',
},
rules: {
required: false,
type: Object,
default: () => {},
},
},
data() {
return {
htmlContent: '',
}
},
computed: {
// Makes content watchable
localContent() {
return this.content
},
},
watch: {
localContent(newValue) {
if (this.md) {
this.htmlContent = this.md.render(newValue)
}
},
},
async created() {
const Markdown = (await import('markdown-it')).default
this.md = new Markdown()
this.md.renderer.rules = { ...this.md.renderer.rules, ...this.rules }
this.htmlContent = this.md.render(this.content)
},
}
</script>