Skip to content

fix(workbench): leave a reply alone when it has code the emphasis scan does not track - #6712

Closed
liugddx wants to merge 3 commits into
rust-previewfrom
fix/cjk-emphasis-quoted-code
Closed

liugddx wants to merge 3 commits into
rust-previewfrom
fix/cjk-emphasis-quoted-code

Conversation

@liugddx

@liugddx liugddx commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Summary

Follow-up to #6658. The CJK emphasis repair could change literal code inside blockquotes and lists, or text inside raw HTML blocks. For example, - > **原文:**继续 was rewritten to - > **原文**:继续, changing the code block's contents.

Replies containing potentially indented code behind mixed quote/list prefixes, HTML tag lines (including closing and custom tags), or raw HTML comment/declaration/processing-instruction openers now remain byte-identical. This also covers CDATA and raw HTML bodies spanning blank lines. Ordinary list and quote prose still receives the emphasis repair.

The guard deliberately skips the entire reply, including ambiguous tag lines: some prose may retain visible asterisks. It avoids expanding the line scan into another Markdown parser. The Markdown parser in third-party/nsh is synchronized from upstream.

Verification

  • Workbench JavaScript suite: 160 tests passed with Node 24.21.0.
  • Markdown-emphasis suite: 13 tests passed. Running the updated suite against the original PR module at 0c515f799 produces 11 passes and 2 failures, covering the nested-container and raw-HTML regressions.
  • A temporary harness linked to the project's locked markdown parser verified 5 nested-code fixtures and 9 HTML-block fixtures; the production repair preserves each input exactly. The HTML cases include genuinely unclosed processing instructions and declarations.
  • Biome checks on both changed files and git diff --check passed.
  • UI TypeScript check passed using fresh declarations from the existing ui_types generator and the current workbench sources.
  • Not run locally: native desktop rendering or clipboard interactions. The parser and function checks above provide the behavioral evidence; GitHub CI validates the pushed commits.

AI use

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

Tool(s) and scope: Claude Code authored the initial guard and tests. Codex implemented the mixed-container and raw-HTML follow-up, validated the behavior, and updated this description. Material AI-authored commits carry Generated-by trailers.

Checklist

  • Tests cover the change and fail without it
  • Format, typecheck and the affected suites pass locally

Does this PR entail a change in behavior?

  • Yes — described under Summary above
  • No

…n does not track

Post-merge review of #6658 found two cases where the scan still rewrote a code body:
indented code inside a blockquote, and raw HTML blocks (`<pre>` and similar) whose body
runs across blank lines. The scan reads one line at a time and does not follow either.

Rather than grow the scan, a reply that contains one of these is left exactly as
written. The worst case is a stray asterisk; it is never a changed code body.

Generated-by: Claude Code
Co-Authored-By: Claude Opus 5.5 <[email protected]>

@Astro-Han Astro-Han left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed both changed files at 0c515f79998b8ea0703ccd106aa5f1bf4e9b46fc. The new guard preserves the supplied top-level quoted-code and raw-HTML examples, but one P2 remains: quoted indented code inside a list is still rewritten. The inline comment at markdownEmphasis.ts:281 contains the reproducer.

I ran the exact current Markdown-emphasis test file with Node 24: all 12 tests pass. Replacing only the production module with its incoming-base version makes the newly added test fail (11 pass, one fail), confirming the intended cases are repaired. I also passed two counterexamples through the actual production function and the same markdown 1.0.0 parser locked by NSH: - > **原文:**继续 and 1. > **原文:**继续. Both parse as code blocks before and after processing, but the code value changes from **原文:**继续 to **原文**:继续. I checked the BotReply call site and native code-block conversion; this is a changed literal code body, not an emphasis-only difference. I did not run a native desktop or clipboard interaction.

An actual merge with current rust-preview 75fe3d0e059c58b798782604668f37b56a420255 succeeds. CI 42565747315 has completed with failure. I read its macOS log: all 22 Desktop tests pass, then the second pixel test fails while loading the unchanged fixture that binds the reserved Cmd+H shortcut. That failure is separate from this PR's two-file text change and from the P2 above. There is no database schema or protocol change.


Automated review notice: This comment was posted by an automated review agent operated by Astro-Han. It is not an independent human review and does not replace one.

* body can run across blank lines. A reply that has one is left exactly as written, so the
* worst case is a stray asterisk and never a changed code body.
*/
const UNMODELLED = /^[ \t]*(?:>[ \t]*)+(?: {4,}|\t)|<(?:pre|script|style|textarea)\b|<!--/imu;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Include list containers when guarding quoted code. For a Bot reply containing - > **原文:**继续, this pattern does not match because the first container marker is -, so closeCjkEmphasis returns - > **原文**:继续. The project's locked markdown 1.0.0 parser identifies both versions as a list containing a blockquote containing a code block: its literal code changes from **原文:**继续 to **原文**:继续. The ordered-list form 1. > **原文:**继续 fails identically. BotReply.tsx:49 sends the rewritten string to TextView, whose code-block converter preserves that changed value. The new protection therefore still alters displayed code in this supported container shape. Recognize the surrounding list prefixes, or conservatively leave these replies unchanged, and add these cases.


Automated review notice: This comment was posted by an automated review agent operated by Astro-Han. It is not an independent human review and does not replace one.

@liugddx
liugddx force-pushed the fix/cjk-emphasis-quoted-code branch from 2e7d8a0 to 6a663ab Compare November 9, 2026 09:02
Use a conservative tag-line guard and verify mixed container and HTML block cases, including unterminated processing instructions and declarations.

Generated-by: Codex
@M4n5ter

M4n5ter commented Nov 9, 2026

Copy link
Copy Markdown
Member

@liugddx

English

Thanks for following up on the #6658 edge cases!

Good news on the premise noted in the description ("A fix inside the Markdown parser would not need to model any of this, but third-party/nsh is synchronized from upstream"): #6708 (cb2cc8958) synchronized third-party/nsh to upstream 323a8663, which already implements the markdown-cjk-friendly CommonMark amendment (commonmark-spec#650) natively inside nsh-base's Rust Markdown parser (third-party/nsh/crates/nsh-base/src/text_view/markdown/cjk.rs + offsets.rs).

Because nsh-base marks CJK-adjacent delimiter runs before running the real markdown-rs CommonMark/GFM AST parser and strips/remaps offsets afterward (offsets::restore):

  • All CJK **bold** (as well as *italic* and ~~strikethrough~~) cases in markdown-emphasis.test.mjs—plus cases markdownEmphasis.ts previously left unfixed (他说**“甲”和“乙”**都是重点, **营收(同比 +12%)**增长明显, **增长12%**明显)—parse into Inline::Strong directly, consistently across both BotReply.tsx and MarkdownBody.tsx without moving punctuation outside bold.
  • Every code and raw HTML construct—including fenced code, indented code, quoted indented code (> **原文:**继续), list-nested quoted indented code (- > **原文:**继续, which UNMODELLED here still misses), and <pre> / <script> / <!-- --> across blank lines—stays byte-identical without disabling CJK emphasis across the rest of a reply when <!-- or <pre> appears.

Closing #6712 rather than extending the JS line-scanner pass—could you open a clean follow-up PR that:

  1. Deletes products/maka/workbench/app/markdownEmphasis.ts and products/maka/workbench/tests/markdown-emphasis.test.mjs,
  2. Restores products/maka/workbench/app/BotReply.tsx (line 49) to markdown={message().text}, and
  3. Adds a focused Rust behavior test verifying CJK emphasis and quoted/list/HTML code preservation through TextView / nsh_base::text_view::Parser?
中文

感谢跟进 #6658 的边界问题!

关于描述中提到的前提(“如果在 Markdown 解析器内部修复就不需要建模这些情况,但 third-party/nsh 从上游同步”),有一个好消息:刚刚合入的 #6708(cb2cc8958)已将 third-party/nsh 同步至上游 323a8663,其中 nsh-base 的 Rust Markdown 解析器内部已经原生实现了 markdown-cjk-friendly 规范(commonmark-spec#650)(见 third-party/nsh/crates/nsh-base/src/text_view/markdown/cjk.rs 与 offsets.rs)。

由于 nsh-base 直接在真实 markdown-rs CommonMark/GFM AST 解析前后处理定界符与源码偏移还原(offsets::restore):

  • 原 markdown-emphasis.test.mjs 中的中文加粗场景(以及此前 JS 扫描器放弃处理的 他说**“甲”和“乙”**都是重点、**营收(同比 +12%)**增长明显、**增长12%**明显,外加 *斜体* 与 ~~删除线~~)均已原生闭合为 Inline::Strong,且 BotReply.tsx 与 MarkdownBody.tsx 行为完全一致、不再挪动原文标点位置;
  • 所有围栏代码、缩进代码、引用缩进代码(> **原文:**继续)、列表嵌套引用缩进代码(- > **原文:**继续,当前 UNMODELLED 仍会漏判篡改)以及跨空行 <pre> / <script> / <!-- --> 均天然字节级无损,也不会因为回复某处带有 <!-- 或 <pre> 就导致整条回复的中文加粗失效。

因此这里先关闭 #6712,不再继续维护 JS 逐行扫描补丁;麻烦重新提一个清理 PR:

  1. 删除 products/maka/workbench/app/markdownEmphasis.ts 与 products/maka/workbench/tests/markdown-emphasis.test.mjs;
  2. 将 products/maka/workbench/app/BotReply.tsx(第 49 行)改回 markdown={message().text};
  3. 补一个精简的 Rust 行为测试,覆盖 TextView / nsh_base::text_view::Parser 下的中文强调闭合及引用/列表代码块原样保留。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants