From a9cd05e960793b653fcfc25eb8e77cf2da4fe87c Mon Sep 17 00:00:00 2001 From: tianma-if Date: Sat, 12 Sep 2026 00:07:05 +0800 Subject: [PATCH] feat(web): highlight Markdown source and switch themes from the toolbar Light auto theme now colors headings, marks, quotes, and links so source mode is readable. The editor toolbar can pick the same Markdown themes as settings. --- apps/web/package.json | 1 + apps/web/src/components/EditorToolbar.tsx | 21 +++++++++++- apps/web/src/components/ThemeProvider.tsx | 8 +++++ .../editor/MarkdownSourceEditor.tsx | 17 +++++----- apps/web/src/lib/markdown-source-highlight.ts | 32 +++++++++++++++++++ apps/web/src/lib/markdown-theme.test.mjs | 28 ++++++++++++++++ bun.lock | 3 +- packages/shared/src/i18n/en-US.ts | 1 + packages/shared/src/i18n/zh-CN.ts | 1 + 9 files changed, 102 insertions(+), 10 deletions(-) create mode 100644 apps/web/src/lib/markdown-source-highlight.ts diff --git a/apps/web/package.json b/apps/web/package.json index 700e4dc0..b9975f8f 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -6,6 +6,7 @@ "dependencies": { "@antv/x6": "3.1.8", "@codemirror/lang-markdown": "^6.5.2", + "@lezer/highlight": "^1.2.3", "@edgeever/client": "workspace:*", "@floating-ui/react-dom": "^2.1.8", "@fontsource-variable/noto-sans-sc": "^5.2.8", diff --git a/apps/web/src/components/EditorToolbar.tsx b/apps/web/src/components/EditorToolbar.tsx index 697919cb..82b2038d 100644 --- a/apps/web/src/components/EditorToolbar.tsx +++ b/apps/web/src/components/EditorToolbar.tsx @@ -35,6 +35,7 @@ import { import { CODE_BLOCK_LANGUAGES, getCodeBlockLanguageValue } from "@/lib/code-block"; import { EditorTableMenu } from "@/components/EditorTableMenu"; import { wrapIndentedParagraphInList } from "@/lib/editor-shortcuts"; +import { MARKDOWN_THEME_PREFERENCES, useMarkdownTheme } from "@/components/ThemeProvider"; const EditorToolbarButton = ({ active = false, @@ -159,6 +160,7 @@ export const EditorToolbar = ({ externalLinkActive?: boolean; }) => { const { t } = useTranslation(); + const { markdownThemePreference, setMarkdownTheme } = useMarkdownTheme(); const controlsRef = useRef(null); const [expanded, setExpanded] = useState(readEditorToolbarExpandedPreference); const [hasOverflow, setHasOverflow] = useState(false); @@ -366,7 +368,24 @@ export const EditorToolbar = ({ )} {markdownMode ? ( - {t("editorToolbar.markdownSource")} + ) : ( <>