初始化

This commit is contained in:
李琦
2026-01-15 14:57:36 +08:00
parent 20e6e9fb3f
commit a43dc4c7fb
7 changed files with 107 additions and 15878 deletions

View File

@@ -0,0 +1,33 @@
<template>
<code ref="codeBlock" :class="languageClass">{{ code }}</code>
</template>
<script setup lang="ts">
import { ref, onMounted, watch, nextTick } from 'vue'
import hljs from 'highlight.js'
const props = defineProps<{
code: string
language: string
}>()
const codeBlock = ref<HTMLElement | null>(null)
const languageClass = `language-${props.language || 'plaintext'}`
const highlight = () => {
if (codeBlock.value) {
// Reset internal state if needed, though highlighting overwrites innerHTML
delete codeBlock.value.dataset.highlighted
hljs.highlightElement(codeBlock.value)
}
}
onMounted(() => {
highlight()
})
watch(() => props.code, () => {
nextTick(highlight)
})
</script>