IntelliClass_FE/components/MarkdownRenderer.vue
Timothy Yin 49b9e97ee8
Some checks failed
CI / test (push) Failing after 1m12s
CI / lint (push) Failing after 14m36s
feat: 完成教学设计模块(除了课程图谱),添加了炫酷的思考中动画
2025-04-27 18:51:40 +08:00

50 lines
1.0 KiB
Vue

<script setup lang="ts">
import md from 'markdown-it'
import hljs from 'highlight.js'
import 'highlight.js/styles/github-dark-dimmed.min.css'
const renderer = md({
html: true,
linkify: true,
typographer: true,
breaks: true,
highlight: function (str, lang) {
if (lang && hljs.getLanguage(lang)) {
try {
return `<pre class="hljs" style="overflow-x: auto"><code>${
hljs.highlight(str, { language: lang, ignoreIllegals: true }).value
}</code></pre>`
} catch {
/* ignore */
}
}
return (
'<pre class="hljs"><code>' + md().utils.escapeHtml(str) + '</code></pre>'
)
},
})
defineProps({
source: {
type: String,
required: true,
},
})
</script>
<template>
<article
class="prose dark:prose-invert max-w-none prose-sm prose-neutral"
v-html="
renderer.render(source.replaceAll('\t', '&nbsp;&nbsp;&nbsp;&nbsp;'))
"
></article>
</template>
<style>
think {
@apply block my-4 p-3 bg-blue-500/5 border-l-4 border-primary/30 rounded italic text-xs;
}
</style>