Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/renderer/src/pages/home/Markdown/Markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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(() => {
Expand Down
8 changes: 8 additions & 0 deletions src/renderer/src/utils/formats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>`
)
}