fix: Improve null handling in code block and syntax highlighting

This commit is contained in:
kangfenmao 2025-02-20 12:04:29 +08:00
parent 39fe583030
commit 31b0fbf775
2 changed files with 2 additions and 1 deletions

View File

@ -60,7 +60,7 @@ export const SyntaxHighlighterProvider: React.FC<PropsWithChildren> = ({ childre
const mappedLanguage = languageMap[language] || language const mappedLanguage = languageMap[language] || language
code = code.trimEnd() code = code?.trimEnd() ?? ''
const escapedCode = code?.replace(/[<>]/g, (char) => ({ '<': '&lt;', '>': '&gt;' })[char]!) const escapedCode = code?.replace(/[<>]/g, (char) => ({ '<': '&lt;', '>': '&gt;' })[char]!)
try { try {

View File

@ -154,6 +154,7 @@ const CopyButton: React.FC<{ text: string; style?: React.CSSProperties }> = ({ t
const { t } = useTranslation() const { t } = useTranslation()
const onCopy = () => { const onCopy = () => {
if (!text) return
navigator.clipboard.writeText(text) navigator.clipboard.writeText(text)
window.message.success({ content: t('message.copied'), key: 'copy-code' }) window.message.success({ content: t('message.copied'), key: 'copy-code' })
setCopied(true) setCopied(true)