fix: update citation rendering logic in MainTextBlock component

- Added a check to determine if the citation URL is a valid link.
- Updated citation tag formatting to conditionally include the link based on the URL validity.
This commit is contained in:
kangfenmao 2025-05-09 15:49:02 +08:00
parent 28f1e486e6
commit 5b95d20294

View File

@ -57,8 +57,10 @@ const MainTextBlock: React.FC<Props> = ({ block, citationBlockId, role, mentions
title: citation.title || citation.hostname || '',
content: citation.content?.substring(0, 200)
}
const isLink = citation.url.startsWith('http')
const citationJson = encodeHTML(JSON.stringify(supData))
const citationTag = `[<sup data-citation='${citationJson}'>${citationNum}</sup>](${citation.url})`
const supTag = `<sup data-citation='${citationJson}'>${citationNum}</sup>`
const citationTag = isLink ? `[${supTag}](${citation.url})` : supTag
// Replace all occurrences of [citationNum] with the formatted citation
const regex = new RegExp(`\\[${citationNum}\\]`, 'g')