feat(frontend): polish chat suggestions, citations, and drawers

- unify suggested-question styling across chat entry points
- keep citation markers inline with their preceding list content
- prevent manual editor viewport shifts and synchronize drawer motion
- align embedded preview and editor drawers in the body stacking context
This commit is contained in:
wizardchen
2026-06-17 22:38:07 +08:00
committed by lyingbug
parent e0d3c1dafd
commit 4e2d568149
9 changed files with 305 additions and 313 deletions
@@ -167,10 +167,37 @@ test('renderChatMarkdown inlines consecutive citation tags across newlines', ()
assert.doesNotMatch(html, /<\/p>\s*<p>\s*<span class="citation citation-kb"/)
})
test('joinCitationTagsToPreviousLine keeps citations on a new line after a list', () => {
const tag = '<kb doc="doc.pdf" chunk_id="1" />'
const input = `1. first\n2. second\n\n${tag}`
assert.equal(joinCitationTagsToPreviousLine(input), `1. first\n2. second\n\n${tag}`)
test('joinCitationTagsToPreviousLine appends an indented citation to the preceding list item', () => {
const tag = '<kb doc="阅读之星全国青少年阅读风采展示活动.pdf" chunk_id="chunk-1" />'
const input = [
'#### 5️⃣ 阅读之星培养基地',
'- 每个组别冠亚季军及前十强所在的学校,将获得 **"阅读之星培养基地"** 奖牌',
'',
` ${tag}`,
].join('\n')
assert.equal(
joinCitationTagsToPreviousLine(input),
[
'#### 5️⃣ 阅读之星培养基地',
`- 每个组别冠亚季军及前十强所在的学校,将获得 **"阅读之星培养基地"** 奖牌 ${tag}`,
].join('\n'),
)
})
test('renderChatMarkdown renders a citation after a list item inline in that item', () => {
const renderer = createChatMarkdownRenderer({
imageRenderer: ({ href, text }) => `<img src="${href}" alt="${text}">`,
isValidImageUrl: () => true,
})
const tag = '<kb doc="阅读之星全国青少年阅读风采展示活动.pdf" chunk_id="chunk-1" />'
const html = renderChatMarkdown(`- 培养基地奖牌\n\n ${tag}`, {
renderer,
escapeMarkdown: (text) => text,
sanitizeHtml: (value) => value,
})
assert.match(html, /<li>培养基地奖牌 <span class="citation citation-kb"/)
assert.doesNotMatch(html, /<\/ul>\s*<p>\s*<span class="citation citation-kb"/)
})
test('joinCitationTagsToPreviousLine does not merge citations onto fenced code closing delimiter', () => {
+6 -7
View File
@@ -224,16 +224,15 @@ export function joinCitationTagsToPreviousLine(content: string): string {
)
}
// Blank lines before citations: join to previous prose, but keep a break after lists
// or fenced-code delimiters (``` / ~~~ must stay on their own line).
// Blank lines before citations: join to the previous content. Fenced-code
// delimiters are the only exception because ``` / ~~~ must stay on their own line.
result = result.replace(/\n[ \t]*\n+([ \t]*<(?:kb|web)\b)/gi, (match, kbStart, offset, full) => {
const before = full.slice(0, offset)
const lastLine = before.split('\n').filter((line) => line.trim()).pop() || ''
const isListItem = /^\s*(\d+\.|[-*+])\s+\S/.test(lastLine)
if (isListItem || isFencedCodeDelimiterLine(lastLine)) {
const lastLine = before.split('\n').filter((line: string) => line.trim()).pop() || ''
if (isFencedCodeDelimiterLine(lastLine)) {
return `\n\n${kbStart}`
}
return ` ${kbStart}`
return ` ${kbStart.trimStart()}`
})
// Single newline before citation when it follows text or another citation (not after a blank line)
@@ -243,7 +242,7 @@ export function joinCitationTagsToPreviousLine(content: string): string {
if (isFencedCodeDelimiterLine(beforePart)) {
return match
}
return `${beforePart} ${kbStart}`
return `${beforePart} ${kbStart.trimStart()}`
},
)