fix(chat): refine markdown typography

This commit is contained in:
2026-07-17 14:33:26 +08:00
parent c7bafda135
commit 9173267e09
6 changed files with 96 additions and 24 deletions

View File

@@ -23,9 +23,17 @@ const reasoning = computed(() => props.reasoning || parsed.value.reasoning);
const hasAnswer = computed(() => answer.value.trim().length > 0);
const renderedContent = computed(() => {
if (props.role !== "assistant") return answer.value;
return hasAnswer.value ? markdown.render(answer.value) : "";
return hasAnswer.value ? markdown.render(normalizeStandaloneHeadings(answer.value)) : "";
});
function normalizeStandaloneHeadings(content: string) {
return content.replace(/^([ \t]*)\*\*(.+)\*\*[ \t]*$/gm, (line, indent: string, title: string) => {
const normalizedTitle = title.trim();
if (!normalizedTitle || normalizedTitle.length > 48 || normalizedTitle.includes("**")) return line;
return `${indent}### ${normalizedTitle}`;
});
}
function splitReasoning(content: string) {
const lower = content.toLowerCase();
let answer = "";