feat: 统一聊天 Markdown 渲染
- 新增 ChatTimeMarkdown 并在管理端、用户端聊天入口复用 - 收敛聊天页面重复 Markdown 样式,保留工具和思考块独立渲染
This commit is contained in:
@@ -1,11 +1,9 @@
|
||||
<script setup lang="ts">
|
||||
import type { ChatTimeTimelineItem } from '@easyflow/types';
|
||||
|
||||
import { XMarkdown as ElXMarkdown } from 'vue-element-plus-x';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { ChatThinkingBlock } from '@easyflow/common-ui';
|
||||
import { ChatThinkingBlock, ChatTimeMarkdown } from '@easyflow/common-ui';
|
||||
import { IconifyIcon } from '@easyflow/icons';
|
||||
import { useUserStore } from '@easyflow/stores';
|
||||
|
||||
@@ -200,7 +198,7 @@ async function handleCopy(item: ChatTimeTimelineItem) {
|
||||
:status="segment.status"
|
||||
class="chat-thinking-block-item"
|
||||
/>
|
||||
<ElXMarkdown v-else :markdown="segment.content" />
|
||||
<ChatTimeMarkdown v-else :content="segment.content" />
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
@@ -256,7 +254,7 @@ async function handleCopy(item: ChatTimeTimelineItem) {
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<ElXMarkdown v-else :markdown="item.content" />
|
||||
<ChatTimeMarkdown v-else :content="item.content" />
|
||||
</template>
|
||||
|
||||
<template #footer="{ item }">
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
"qrcode": "catalog:",
|
||||
"tippy.js": "catalog:",
|
||||
"vue": "catalog:",
|
||||
"vue-element-plus-x": "catalog:",
|
||||
"vue-json-viewer": "catalog:",
|
||||
"vue-router": "catalog:",
|
||||
"vue-tippy": "catalog:"
|
||||
|
||||
@@ -0,0 +1,308 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
import { XMarkdown as ElXMarkdown } from 'vue-element-plus-x';
|
||||
|
||||
import { usePreferences } from '@easyflow-core/preferences';
|
||||
|
||||
interface Props {
|
||||
content?: string;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
content: '',
|
||||
});
|
||||
const { isDark } = usePreferences();
|
||||
const normalizedContent = computed(() => String(props.content || ''));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ElXMarkdown
|
||||
class="chat-time-markdown"
|
||||
:allow-html="false"
|
||||
:enable-breaks="true"
|
||||
:enable-code-line-number="false"
|
||||
:enable-latex="true"
|
||||
:default-theme-mode="isDark ? 'dark' : 'light'"
|
||||
:markdown="normalizedContent"
|
||||
:need-view-code-btn="false"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.chat-time-markdown {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
color: hsl(var(--text-strong));
|
||||
font-size: 14px;
|
||||
line-height: 1.72;
|
||||
overflow-wrap: anywhere;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.chat-time-markdown :deep(.elx-xmarkdown-container),
|
||||
.chat-time-markdown :deep(.elx-xmarkdown-provider),
|
||||
.chat-time-markdown :deep(.markdown-body) {
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
color: inherit;
|
||||
font-size: inherit;
|
||||
line-height: inherit;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.chat-time-markdown :deep(.markdown-body) {
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.chat-time-markdown :deep(.markdown-body > :first-child) {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.chat-time-markdown :deep(.markdown-body > :last-child) {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.chat-time-markdown :deep(h1),
|
||||
.chat-time-markdown :deep(h2),
|
||||
.chat-time-markdown :deep(h3),
|
||||
.chat-time-markdown :deep(h4),
|
||||
.chat-time-markdown :deep(h5),
|
||||
.chat-time-markdown :deep(h6) {
|
||||
margin: 1.35em 0 0.62em;
|
||||
color: hsl(var(--text-strong));
|
||||
font-weight: 650;
|
||||
line-height: 1.28;
|
||||
letter-spacing: 0;
|
||||
}
|
||||
|
||||
.chat-time-markdown :deep(h1) {
|
||||
font-size: 1.55em;
|
||||
}
|
||||
|
||||
.chat-time-markdown :deep(h2) {
|
||||
font-size: 1.34em;
|
||||
}
|
||||
|
||||
.chat-time-markdown :deep(h3) {
|
||||
font-size: 1.18em;
|
||||
}
|
||||
|
||||
.chat-time-markdown :deep(h4) {
|
||||
font-size: 1.06em;
|
||||
}
|
||||
|
||||
.chat-time-markdown :deep(h5),
|
||||
.chat-time-markdown :deep(h6) {
|
||||
font-size: 1em;
|
||||
}
|
||||
|
||||
.chat-time-markdown :deep(p) {
|
||||
margin: 0.72em 0;
|
||||
font-size: inherit;
|
||||
line-height: inherit;
|
||||
}
|
||||
|
||||
.chat-time-markdown :deep(strong) {
|
||||
color: hsl(var(--text-strong));
|
||||
font-weight: 650;
|
||||
}
|
||||
|
||||
.chat-time-markdown :deep(em) {
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.chat-time-markdown :deep(del) {
|
||||
color: hsl(var(--text-muted));
|
||||
}
|
||||
|
||||
.chat-time-markdown :deep(a) {
|
||||
color: hsl(var(--primary));
|
||||
text-decoration: underline;
|
||||
text-underline-offset: 3px;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.chat-time-markdown :deep(a:hover) {
|
||||
color: hsl(var(--primary) / 0.82);
|
||||
}
|
||||
|
||||
.chat-time-markdown :deep(hr) {
|
||||
height: 1px;
|
||||
margin: 1.25em 0;
|
||||
background: hsl(var(--divider-faint) / 0.84);
|
||||
border: 0;
|
||||
}
|
||||
|
||||
.chat-time-markdown :deep(blockquote) {
|
||||
margin: 0.95em 0;
|
||||
padding: 8px 12px;
|
||||
color: hsl(var(--text-muted));
|
||||
background: hsl(var(--surface-subtle) / 0.72);
|
||||
border-left: 3px solid hsl(var(--primary) / 0.32);
|
||||
border-radius: 0 10px 10px 0;
|
||||
}
|
||||
|
||||
.chat-time-markdown :deep(blockquote > :first-child) {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.chat-time-markdown :deep(blockquote > :last-child) {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.chat-time-markdown :deep(ul),
|
||||
.chat-time-markdown :deep(ol) {
|
||||
margin: 0.72em 0;
|
||||
padding-left: 1.45em;
|
||||
}
|
||||
|
||||
.chat-time-markdown :deep(ul) {
|
||||
list-style: disc;
|
||||
}
|
||||
|
||||
.chat-time-markdown :deep(ol) {
|
||||
list-style: decimal;
|
||||
}
|
||||
|
||||
.chat-time-markdown :deep(ul ul),
|
||||
.chat-time-markdown :deep(ol ul) {
|
||||
list-style: circle;
|
||||
}
|
||||
|
||||
.chat-time-markdown :deep(ul ul ul),
|
||||
.chat-time-markdown :deep(ol ul ul) {
|
||||
list-style: square;
|
||||
}
|
||||
|
||||
.chat-time-markdown :deep(li) {
|
||||
margin: 0.28em 0;
|
||||
padding-left: 0.12em;
|
||||
}
|
||||
|
||||
.chat-time-markdown :deep(li > p) {
|
||||
margin: 0.36em 0;
|
||||
}
|
||||
|
||||
.chat-time-markdown :deep(li.task-list-item) {
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
.chat-time-markdown :deep(.task-list-item-checkbox) {
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
margin: 0 0.48em 0 -1.45em;
|
||||
vertical-align: -0.12em;
|
||||
accent-color: hsl(var(--primary));
|
||||
}
|
||||
|
||||
.chat-time-markdown :deep(table) {
|
||||
display: block;
|
||||
width: max-content;
|
||||
max-width: 100%;
|
||||
margin: 1em 0;
|
||||
overflow: auto;
|
||||
border-spacing: 0;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
.chat-time-markdown :deep(th),
|
||||
.chat-time-markdown :deep(td) {
|
||||
min-width: 96px;
|
||||
padding: 8px 10px;
|
||||
vertical-align: top;
|
||||
border: 1px solid hsl(var(--divider-faint) / 0.88);
|
||||
}
|
||||
|
||||
.chat-time-markdown :deep(th) {
|
||||
color: hsl(var(--text-strong));
|
||||
font-weight: 650;
|
||||
background: hsl(var(--surface-subtle));
|
||||
}
|
||||
|
||||
.chat-time-markdown :deep(tr:nth-child(2n) td) {
|
||||
background: hsl(var(--surface-subtle) / 0.42);
|
||||
}
|
||||
|
||||
.chat-time-markdown :deep(code) {
|
||||
padding: 0.12em 0.34em;
|
||||
color: hsl(var(--primary));
|
||||
font-size: 0.92em;
|
||||
font-family:
|
||||
ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono',
|
||||
'Courier New', monospace;
|
||||
background: hsl(var(--surface-subtle));
|
||||
border: 1px solid hsl(var(--divider-faint) / 0.7);
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.chat-time-markdown :deep(pre) {
|
||||
max-width: 100%;
|
||||
margin: 1em 0;
|
||||
padding: 12px 14px;
|
||||
overflow: auto;
|
||||
color: hsl(var(--text-strong));
|
||||
background: hsl(var(--surface-subtle));
|
||||
border: 1px solid hsl(var(--divider-faint) / 0.82);
|
||||
border-radius: 12px;
|
||||
}
|
||||
|
||||
.chat-time-markdown :deep(pre code) {
|
||||
display: block;
|
||||
min-width: max-content;
|
||||
padding: 0;
|
||||
color: inherit;
|
||||
font-size: 0.92em;
|
||||
line-height: 1.68;
|
||||
background: transparent;
|
||||
border: 0;
|
||||
border-radius: 0;
|
||||
overflow-wrap: normal;
|
||||
word-break: normal;
|
||||
}
|
||||
|
||||
.chat-time-markdown :deep(.shiki),
|
||||
.chat-time-markdown :deep(.shiki code) {
|
||||
background: transparent !important;
|
||||
}
|
||||
|
||||
.chat-time-markdown :deep(img) {
|
||||
display: block;
|
||||
max-width: min(100%, 460px);
|
||||
height: auto;
|
||||
margin: 1em 0;
|
||||
border: 1px solid hsl(var(--divider-faint) / 0.82);
|
||||
border-radius: 12px;
|
||||
}
|
||||
|
||||
.chat-time-markdown :deep(.katex-display) {
|
||||
max-width: 100%;
|
||||
margin: 1em 0;
|
||||
overflow-x: auto;
|
||||
overflow-y: hidden;
|
||||
}
|
||||
|
||||
.chat-time-markdown :deep(.katex) {
|
||||
font-size: 1em;
|
||||
}
|
||||
|
||||
.chat-time-markdown :deep(.mermaid),
|
||||
.chat-time-markdown :deep([class*='mermaid']) {
|
||||
max-width: 100%;
|
||||
margin: 1em 0;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.chat-time-markdown :deep(svg) {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
:global(.dark) .chat-time-markdown :deep(blockquote) {
|
||||
background: hsl(var(--surface-subtle) / 0.5);
|
||||
}
|
||||
|
||||
:global(.dark) .chat-time-markdown :deep(code),
|
||||
:global(.dark) .chat-time-markdown :deep(pre) {
|
||||
background: hsl(var(--surface-subtle) / 0.78);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1 @@
|
||||
export { default as ChatTimeMarkdown } from './ChatTimeMarkdown.vue';
|
||||
@@ -1,5 +1,6 @@
|
||||
export * from './api-component';
|
||||
export * from './captcha';
|
||||
export * from './chat-markdown';
|
||||
export * from './chat-thinking';
|
||||
export * from './col-page';
|
||||
export * from './count-to';
|
||||
|
||||
3
easyflow-ui-usercenter/pnpm-lock.yaml
generated
3
easyflow-ui-usercenter/pnpm-lock.yaml
generated
@@ -1342,6 +1342,9 @@ importers:
|
||||
vue:
|
||||
specifier: ^3.5.17
|
||||
version: 3.5.24(typescript@5.9.3)
|
||||
vue-element-plus-x:
|
||||
specifier: 'catalog:'
|
||||
version: 1.3.7(rollup@4.53.2)(vue@3.5.24(typescript@5.9.3))
|
||||
vue-json-viewer:
|
||||
specifier: 'catalog:'
|
||||
version: 3.0.4(vue@3.5.24(typescript@5.9.3))
|
||||
|
||||
Reference in New Issue
Block a user