-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathTiptapRenderer.vue
More file actions
47 lines (39 loc) · 1 KB
/
TiptapRenderer.vue
File metadata and controls
47 lines (39 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<script setup lang="ts">
import { Editor, EditorContent, useEditor } from "@tiptap/vue-3";
import hljs from "highlight.js";
import { computed, onMounted, ref, ShallowRef } from "vue";
import { tiptapRenderedExtensions } from "./tiptap-extensions";
const props = defineProps<{
document: string;
}>();
const parsedDocument = computed(() => {
try {
return JSON.parse(props.document);
} catch {
return props.document;
}
});
const editor = useEditor({
editorProps: {
attributes: { class: `tiptap--rendered` }
},
editable: false,
content: parsedDocument.value,
extensions: tiptapRenderedExtensions
}) as ShallowRef<Editor>;
const contentRef = ref<HTMLDivElement>();
onMounted(() => {
contentRef.value?.querySelectorAll("pre code").forEach((el) => {
hljs.highlightElement(el as HTMLElement);
});
});
</script>
<template>
<div ref="contentRef">
<editor-content :editor="editor" />
</div>
</template>
<style>
@import url("./tiptap.css");
@import url("./tiptap-hljs.css");
</style>