Files
qiming/qiming-mobile/subpackages/components/markdown-msg/markdown-msg.uvue

42 lines
1.2 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<!-- AI校验通过后需要水平滚动表格时需要设置 scroll-table="true" -->
<mp-html
:content="processedText"
:markdown="true"
:container-style="`width: 100%;`"
:scroll-table="true"
@linktap="handleLinkTap"
/>
</template>
<script lang="uts" setup>
import { replaceMathBracket, groupMarkdownContainers } from '@/utils/markdown.uts'
import mpHtml from '@/subpackages/uni_modules/mp-html/components/mp-html/mp-html.vue'
import { handleExternalLink } from '@/utils/system.uts'
// 定义组件属性
const props = withDefaults(defineProps<{
text?: string
}>(), {
text: ''
})
// 处理文本内容,应用数学公式格式转换
const processedText = computed(() => {
if (!props.text || props.text.trim().length === 0) {
return ''
}
// 先处理分组,再处理数学公式
const groupedText = groupMarkdownContainers(props.text)
console.log('groupedText', groupedText)
return replaceMathBracket(groupedText)
})
// 处理链接点击事件
const handleLinkTap = (event: any) => {
const { href } = event.detail
if (href && href.length > 0) {
handleExternalLink(href);
}
}
</script>