fix: 网页链接附带中文标点解析错误

This commit is contained in:
eeee0717 2025-02-13 15:30:11 +08:00 committed by 亢奋猫
parent 30959e2380
commit 16feb49e9e
2 changed files with 13 additions and 3 deletions

View File

@ -2,7 +2,7 @@ import 'katex/dist/katex.min.css'
import { useSettings } from '@renderer/hooks/useSettings'
import { Message } from '@renderer/types'
import { escapeBrackets, removeSvgEmptyLines, withGeminiGrounding } from '@renderer/utils/formats'
import { escapeBrackets, fixPunctuation, removeSvgEmptyLines, withGeminiGrounding } from '@renderer/utils/formats'
import { isEmpty } from 'lodash'
import { FC, useMemo } from 'react'
import { useTranslation } from 'react-i18next'
@ -34,8 +34,10 @@ const Markdown: FC<Props> = ({ message }) => {
const messageContent = useMemo(() => {
const empty = isEmpty(message.content)
const paused = message.status === 'paused'
const content = empty && paused ? t('message.chat.completion.paused') : withGeminiGrounding(message)
return removeSvgEmptyLines(escapeBrackets(content))
let content = empty && paused ? t('message.chat.completion.paused') : withGeminiGrounding(message)
content = removeSvgEmptyLines(escapeBrackets(content))
content = fixPunctuation(content)
return content
}, [message, t])
const rehypePlugins = useMemo(() => {

View File

@ -107,3 +107,11 @@ export function withMessageThought(message: Message) {
return message
}
export function fixPunctuation(text: string): string {
// 将网页链接后的中文标点符号与链接分开
return text.replace(
/(https?:\/\/[^\s)]+)(\p{P})/gu,
`<a href="$1" target="_blank" rel="noreferrer">$1</a><span style="margin-left: 0.2em;">$2</span>`
)
}