mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-19 06:30:10 +08:00
fix: 修复百度云引用格式转换
修复百度云千帆模型返回消息中^[x]^引用格式的转换问题。修正正则表达式,正确解析方括号内的数字组合,并转换为标准[cite:N]格式。 相关Issue: cherry-studio/issues/11958
This commit is contained in:
parent
e38e963cc9
commit
d8b1df6c26
@ -156,13 +156,15 @@ export function normalizeCitationMarks(
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
case WebSearchSource.BAIDU_CLOUD: {
|
case WebSearchSource.BAIDU_CLOUD: {
|
||||||
// 百度云格式: ^[1][4]^ → [cite:1], [cite:4]
|
// 百度云格式: ^[1][4]^ → [cite:1][cite:4]
|
||||||
applyReplacements(/\^\[(\d+(?:\]\[?\d+)*)\]\^/g, (match) => {
|
applyReplacements(/\^\[([^\]]+)\]\^/g, (match) => {
|
||||||
const citationNums = match[1]
|
// match[1]包含方括号内的内容,如 "1][4"
|
||||||
.replace(/^\[/, '')
|
const content = match[1]
|
||||||
.replace(/\]$/g, '')
|
// 解析方括号内的数字,如 "1][4" -> ['1', '4']
|
||||||
|
const citationNums = content
|
||||||
.split('][')
|
.split('][')
|
||||||
.map((num) => parseInt(num, 10))
|
.map((num) => parseInt(num, 10))
|
||||||
|
.filter((num) => !isNaN(num))
|
||||||
|
|
||||||
const citations = citationNums
|
const citations = citationNums
|
||||||
.filter((num) => citationMap.has(num))
|
.filter((num) => citationMap.has(num))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user