11<script setup lang="ts">
2- import { ref , watchEffect } from ' vue'
2+ import { ref , shallowRef } from ' vue'
33import { getHighlighter } from ' #slidev/shiki'
44
55const props = defineProps <{
@@ -9,30 +9,14 @@ const content = defineModel<string>({ required: true })
99
1010const textareaEl = ref <HTMLTextAreaElement | null >(null )
1111
12- const html = ref (' ' )
13-
14- watchEffect ((onCleanup ) => {
15- let canceled = false
16- onCleanup (() => canceled = true )
17-
18- const c = content .value
19- async function updateHtml() {
20- const highlight = await getHighlighter ()
21- if (canceled )
22- return
23- const h = await highlight (c , ' markdown' )
24- if (canceled )
25- return
26- html .value = h
27- }
28- updateHtml ()
29- })
12+ const highlight = shallowRef <Awaited <ReturnType <typeof getHighlighter >> | null >(null )
13+ getHighlighter ().then (h => highlight .value = h )
3014 </script >
3115
3216<template >
33- <div class =" absolute inset-x-3 inset-y-2 font-mono overflow-x-hidden overflow-y-auto" >
34- <div class =" relative w-full h-max" >
35- <div class =" relative w-full h-max" v-html =" html " />
17+ <div class =" absolute left-3 right-0 inset-y-2 font-mono overflow-x-hidden overflow-y-auto cursor-text " >
18+ <div v-if = " highlight " class =" relative w-full h-max min-h-full " >
19+ <div class =" relative w-full h-max" v-html =" `${highlight(content, 'markdown')} & nbsp ; ` " />
3620 <textarea
3721 ref =" textareaEl" v-model =" content" :placeholder =" props.placeholder"
3822 class =" absolute inset-0 resize-none text-transparent bg-transparent focus:outline-none caret-black dark:caret-white overflow-y-hidden"
0 commit comments