From 09e6756efefa1026a67d28df09db7e5e5e50274d Mon Sep 17 00:00:00 2001 From: zhouxl Date: Mon, 30 Dec 2024 16:46:01 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E5=8D=95=E8=A1=8CCodeBlo?= =?UTF-8?q?ck=E4=B8=AD=E6=98=BE=E7=A4=BAsub?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + src/renderer/src/pages/home/Markdown/CodeBlock.tsx | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index e3f5bfe36..0841e1043 100644 --- a/package.json +++ b/package.json @@ -64,6 +64,7 @@ "adm-zip": "^0.5.16", "apache-arrow": "^18.1.0", "docx": "^9.0.2", + "dompurify": "^3.2.3", "electron-log": "^5.1.5", "electron-store": "^8.2.0", "electron-updater": "^6.3.9", diff --git a/src/renderer/src/pages/home/Markdown/CodeBlock.tsx b/src/renderer/src/pages/home/Markdown/CodeBlock.tsx index 63f6b1a23..e88bb0477 100644 --- a/src/renderer/src/pages/home/Markdown/CodeBlock.tsx +++ b/src/renderer/src/pages/home/Markdown/CodeBlock.tsx @@ -3,6 +3,7 @@ import CopyIcon from '@renderer/components/Icons/CopyIcon' import { useSyntaxHighlighter } from '@renderer/context/SyntaxHighlighterProvider' import { useSettings } from '@renderer/hooks/useSettings' import React, { memo, useEffect, useRef, useState } from 'react' +import DOMPurify from 'dompurify' import { useTranslation } from 'react-i18next' import styled from 'styled-components' @@ -37,6 +38,7 @@ const ExpandButton: React.FC<{ ) } +const ALLOWED_TAGS = ['sub'] // 允许的HTML标签 const CodeBlock: React.FC = ({ children, className }) => { const match = /language-(\w+)/.exec(className || '') @@ -133,7 +135,15 @@ const CodeBlock: React.FC = ({ children, className }) => { {language === 'html' && children?.includes('') && } ) : ( - {children} + ) }