Repository navigation
Conversation
Add lazy Refractor tokenization for Java, Go, Rust, C, C++, C#, and SQL through the existing Astryx CodeBlock tokenizer interface. Preserve source text, normalize aliases, bound streaming work, and cover rendering and clipboard behavior with regression tests. Generated-by: OpenAI Codex
Astro-Han
left a comment
There was a problem hiding this comment.
Automated review notice: This comment was posted by an automated review agent. It is not an independent human review and does not replace one.
Reviewed 147b82a452d4ff7a278b8353e627d5b293d4dd92; I found no P0–P2 issue. I read all nine changed files, including the dependency and notice changes. markdown-body.tsx retains the existing CodeBlock and trust boundaries; markdown-code-highlighting.ts normalizes aliases through the AST and prepares tokens after rendering, while markdown-code-tokenizer.ts maps the seven selected Refractor grammars to Astryx categories. The source, clipboard and rendering remain owned by the existing component.
All 819 UI tests and seven Chromium tests passed locally. These cover UTF-16/CRLF and multiline token ranges, punctuated aliases, literal HTML, existing TypeScript highlighting, streaming/source changes, unmounting, lazy-load failure, copying, collapsing and oversized plain-code fallback. I also repeated three browser checks while replacing only the Markdown component with main's actual module: the head passed all three and main failed all three. I inspected paired light/dark screenshots; the requested language colors are visible and the component layout is retained.
Fresh installation and dependency patches, the normal clean root build:test, UI and Desktop type checks, the production renderer build, 168 architecture tests and the strict architecture comparison with main 59f61cf7, surface inventory, generated third-party notices, ASF headers, Biome and whitespace checks passed. The optional production grammar chunk is 20.15 kB gzip. No protocol or storage change is present; the epoch guard passes at 227. The contribution declares OpenAI Codex and its commit includes the corresponding trailer.
The 20,000 UTF-16-unit limit, 120 ms streaming debounce and bounded cache constrain work, but grammar execution still runs synchronously on the renderer thread; they are not a hard latency guarantee. I did not qualify native OS applications, run the full monorepo suite or perform a production performance benchmark. Exact-head CI test, dependency audit, Linux/Windows packaging and Windows recovery have succeeded, and GitHub reports no merge conflict.
Summary
Fixes #6238
Markdown code blocks for Java, Go, Rust, C/C++, C#, and SQL currently render without syntax colors. This PR adds highlighting through Astryx's existing
tokenizerextension point.CodeBlock, copy button, collapse behavior, and light/dark themes.c++/cppandc#/csharp. Preserve document-global UTF-16 offsets and split multiline tokens at line boundaries.Scope is shared Markdown code blocks. Editors, diff previews, and standalone tool-output code blocks are unchanged.
Highlighting limits
The custom tokenizer reads prepared tokens rather than doing grammar work during React rendering. Streaming updates are debounced by 120 ms, and obsolete results are discarded when the source or language changes.
Extra-language highlighting is limited to 20,000 UTF-16 code units per block. Larger blocks, unknown languages, and highlighting failures remain readable as plain code without truncation. The optional grammar bundle is approximately 20 KB gzipped and loads only when needed.
Verification
Not run: the full all-workspace test suite or native Windows/Linux application tests.
Before and after
The screenshots use the same Markdown snippets, Maka theme, and code-block components before and after the change.
AI use
Tool(s) and scope: OpenAI Codex assisted with implementation, regression tests, local verification, and this PR description. The contributor manually tested the local Desktop build. This PR is published by Codex on the contributor's behalf after their review and approval.
Checklist
Does this PR entail a change in behavior?
简体中文
修改概述
关联并解决 #6238。
目前 Java、Go、Rust、C/C++、C# 和 SQL 的 Markdown 代码块没有语法颜色。本 PR 通过 Astryx 现有的
tokenizer扩展接口补充高亮。CodeBlock、复制按钮、折叠行为和明暗主题。c++/cpp、c#/csharp等语言别名。保留全文 UTF-16 偏移,并按行拆分多行 token,避免后续行高亮错位。修改范围仅限共享 Markdown 代码块,不涉及编辑器、diff 预览或独立的工具输出代码块。
高亮限制
自定义 tokenizer 只读取预先准备好的分词结果,不在 React 渲染过程中执行语法分析。流式更新使用 120 毫秒防抖;代码内容或语言发生变化后,过期结果不会应用到新内容上。
新增语言的高亮上限为每个代码块 20,000 个 UTF-16 代码单元。超过上限、语言未知或高亮失败时,仍完整显示纯文本代码,不截断原文。新增语法包 gzip 后约 20 KB,仅在需要时加载。
验证结果
未执行:全仓库所有工作区测试,以及 Windows/Linux 原生应用测试。
明暗主题的前后对比截图见上方英文正文。
AI 使用说明
OpenAI Codex 协助完成实现、回归测试、本地验证及 PR 描述。贡献者已手动测试本地 Desktop 构建。本 PR 发布前已由贡献者本人审核并批准,由 Codex 代为发布。
检查清单