From aa0b7ed1a82537d49e910b822be9ca32d8ed892a Mon Sep 17 00:00:00 2001 From: one Date: Thu, 12 Jun 2025 16:28:28 +0800 Subject: [PATCH] feat(Markdown): customize table to support source copying (#7019) * feat(Markdown): customize table to support source copying - add a customized table component - update ChatNavigation excluded selectors * refactor: remove redundant feedback * test: add tests for Table --- .../src/pages/home/Markdown/Markdown.tsx | 4 +- .../src/pages/home/Markdown/Table.tsx | 120 +++++++ .../home/Markdown/__tests__/Markdown.test.tsx | 27 ++ .../home/Markdown/__tests__/Table.test.tsx | 316 ++++++++++++++++++ .../__snapshots__/Markdown.test.tsx.snap | 18 + .../__snapshots__/Table.test.tsx.snap | 103 ++++++ .../pages/home/Messages/ChatNavigation.tsx | 3 +- 7 files changed, 589 insertions(+), 2 deletions(-) create mode 100644 src/renderer/src/pages/home/Markdown/Table.tsx create mode 100644 src/renderer/src/pages/home/Markdown/__tests__/Table.test.tsx create mode 100644 src/renderer/src/pages/home/Markdown/__tests__/__snapshots__/Table.test.tsx.snap diff --git a/src/renderer/src/pages/home/Markdown/Markdown.tsx b/src/renderer/src/pages/home/Markdown/Markdown.tsx index d82905cf7f..8ee90a859a 100644 --- a/src/renderer/src/pages/home/Markdown/Markdown.tsx +++ b/src/renderer/src/pages/home/Markdown/Markdown.tsx @@ -24,6 +24,7 @@ import remarkMath from 'remark-math' import CodeBlock from './CodeBlock' import Link from './Link' +import Table from './Table' const ALLOWED_ELEMENTS = /<(style|p|div|span|b|i|strong|em|ul|ol|li|table|tr|td|th|thead|tbody|h[1-6]|blockquote|pre|code|br|hr|svg|path|circle|rect|line|polyline|polygon|text|g|defs|title|desc|tspan|sub|sup)/i @@ -83,6 +84,7 @@ const Markdown: FC = ({ block }) => { code: (props: any) => ( ), + table: (props: any) => , img: (props: any) => , pre: (props: any) =>
,
       p: (props) => {
@@ -91,7 +93,7 @@ const Markdown: FC = ({ block }) => {
         return 

} } as Partial - }, [onSaveCodeBlock]) + }, [onSaveCodeBlock, block.id]) if (messageContent.includes('