Repository navigation
fix(plugin-chatbot): bold next to CJK full-width punctuation renders bold - #34079
Merged
Merged
Conversation
…bold CommonMark's flanking rule reads full-width punctuation as punctuation, so a ** run with a CJK letter on one side and full-width punctuation on the other never opened or closed in chat answers. Every chat markdown surface now renders with remark-cjk-friendly in streamdown's cjk slot, from one shared constant. Claude-Session: https://claude.ai/code/session_01ADHkmRdYmFgg8k5whypBNq Co-authored-by: Claude <noreply@anthropic.com>
… add the changeset The chat renders markdown and never serializes it, so the parseOnly entry keeps the markdown serializer out of the chatbot bundle. Claude-Session: https://claude.ai/code/session_01ADHkmRdYmFgg8k5whypBNq Co-authored-by: Claude <noreply@anthropic.com>
…vendored elements directory Claude-Session: https://claude.ai/code/session_01ADHkmRdYmFgg8k5whypBNq Co-authored-by: Claude <noreply@anthropic.com>
Contributor
Author
|
domain:ui#1 · os-steve · session_01ADHkmT2NE3iyG1o6TDg3sf 席位核对Verdict: ACCEPT · head
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested by Steve · project thread
Fixes #33723
Clause-②: no
Metadata-protocol: none
维护者速读
**、另一侧是全角标点(《》「」,。!?、)时,粗体不再显示成字面星号;做法是给 streamdown 的cjk插槽接上remark-cjk-friendly(新增一个 MIT 依赖,只取解析半边)。**两侧没有空格,定界符判不成开/闭;卡上原例「《书名》,借书人」单独渲染本来就是粗体,真正坏的是借书人是**《书名》**的作者这类「中文字 + ** + 全角标点」。ui/packages/plugin-chatbot/src/chatMarkdownPlugins.ts(插件配置与理由)、ui/packages/plugin-chatbot/src/elements/message.tsx(调用方自带plugins时仍保留 CJK 规则的合并)、pnpm-lock.yaml(只增不改)。pnpm --dir ui exec vitest run packages/plugin-chatbot/src/__tests__/chatAnswerLayout-13032.test.tsx,预期 29 条全绿。What changes
@object-ui/plugin-chatbotadds the dependencyremark-cjk-friendly^2.3.4and imports itsparseOnlyentry.src/chatMarkdownPlugins.ts, exportsCHAT_MARKDOWN_PLUGINS: a streamdownPluginConfigwhosecjkslot carries the plugin inremarkPluginsBefore, so it runs before remark-gfm and owns the emphasis tokenizer.MessageResponse(src/elements/message.tsx) passesplugins={{ ...CHAT_MARKDOWN_PLUGINS, ...plugins }}. A caller that passes its ownpluginskeeps the CJK rule unless it setscjkitself.ReasoningContent(src/elements/reasoning.tsx) passesplugins={CHAT_MARKDOWN_PLUGINS}.src/, notsrc/elements/.src/elements/is the vendored directory thatscripts/check-spec-symbol-derivation.mjsskips, and the package test "the vendored directory stays vendored" refuses a file there with no vendor banner.pnpm-lock.yamlonly gains lines for the new package and its transitive deps. No existing resolution moves.Why
Card premise, corrected. The card's example on its own already renders bold on
origin/main(fb79d47c, streamdown 2.5.0, read withreact-dom/server): in「**《书名》,借书人**」the opener follows「, which is punctuation, so the run is left-flanking. The defect is a CJK letter beside the delimiter, with full-width punctuation on the other side:借书人是**《书名》**的作者: the opener follows a letter and precedes《, so it is not left-flanking.他说**你好,**我们走: the closer follows,and precedes a letter, so it is not right-flanking.CommonMark counts full-width punctuation as punctuation, and a CJK sentence puts no space beside the run, so both stay literal asterisks.
remark-cjk-friendlyimplements the markdown-cjk-friendly rule, which reads a CJK character beside the run the way it reads the whitespace an English sentence would have there.Dependency choice
The tree had nothing CJK-aware (remark-gfm 4.0.1, micromark 4.0.2), and streamdown's
plugins.cjkslot was empty. The seat chose A from three options.remark-cjk-friendly^2.3.4, MIT. It fixes emphasis at the tokenizer (a micromark extension). ItsparseOnlyentry pulls inmicromark-extension-cjk-friendly2.0.2 (MIT),micromark-extension-cjk-friendly-util3.0.1 (MIT) andget-east-asian-width1.6.0 (MIT). The other micromark utilities it needs were already in the tree. The lockfile also records the unused serializer half (mdast-util-to-markdown-cjk-friendly1.0.2,mdast-util-to-markdown2.2.3), because the package declares it. The chat never imports that half, so it is not bundled.@streamdown/cjk1.0.4, Apache-2.0. It is A plus CJK strikethrough and autolink-boundary splitting, which is more surface than the card asks for.**in text nodes. After parsing, an escaped\*\*and a failed delimiter are the same text, so this step would bold escaped asterisks. It is a workaround, not the root fix.Bundle cost was measured with esbuild (minify, ESM, browser) on streamdown with and without the import, with react, mermaid and shiki external:
remark-cjk-friendly/parseOnly(shipped)remark-cjk-friendly(both halves, not shipped)In the Console, the
micromark…/remark-…modules match thevendor-markdowngroup inapps/console/vite.config.ts. That group is tagged$initial. The eager-closure ceiling (ui/scripts/check-eager-closure-budget.mjs) is judged in CI by the Build & E2E UI job. It was not measured locally, because a full Console build was out of scope for this card.Tests
Pins go in the existing
MessageResponseharness,src/__tests__/chatAnswerLayout-13032.test.tsx, as a new top-leveldescribe: "bold next to CJK full-width punctuation (objectstack#33723)". No existing test was edited.《and before「; a closer after,。!?、」, each before a CJK letter.「**《书名》,借书人**」; bold ending before,。!?、」; bold starting after「.**bold**,foo**bar**baz);a**"b"**cstays literal, as CommonMark says; escaped\*\*《书名》\*\*stays literal;**inside an inline code span stays literal.pluginskeeps the CJK rule; the reasoning panel renders with the same rule.Ablation: remove the plugin from CHAT_MARKDOWN_PLUGINS
node scripts/ablation-replace.mjs --file ui/packages/plugin-chatbot/src/elements/markdown-plugins.ts --anchor 'PluginConfig = { cjk: CJK_EMPHASIS };' --replacement 'PluginConfig = { /* ablated */ };'. This ran on commit8bc8bf07, before the module moved tosrc/. The ui vitest resolves@object-ui/*to source, so no build is needed between the mutation and the run.The 10 reds are exactly the 8 failing cases plus the 2 wiring pins. All 19 controls stayed green.
Runs at head ac2b0a1
Acceptance notes
ui/packages/plugin-chatbot/README.md› "Bundle considerations" lists the package's markdown dependencies (streamdown,shiki,mermaid,katex) and does not name the new small parser extension. It was left as is because the section is about the heavy chunks.message.tsxandreasoning.tsxare all on lines this diff does not touch (0 errors).Verification
Local gates:
node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack, run at headac2b0a14, each command's exit code captured before any pipe, then reconciled with--ran:pnpm --dir ui exec vitest run scripts/(Test Files 171 passed, 2 skipped; Tests 5065 passed, 2 skipped),check:undeclared-dep-imports,check:override-consistency,check-osv-exemptions,check-empty-changeset --base origin/main,check-changeset-no-majorandcheck:changeset-fixed.check:dual-build-cjs-loads. It reported PREREQUISITE NOT MET (exit 3) because it reads the builtdist/of every dual-build@objectstack/*package, and this container did not build them. The lockfile is the only path that derives this family, and the lockfile change adds packages to@object-ui/plugin-chatbotalone. CI's Lint & Repo Gates job runs it.pnpm check:new-line-citations(ui): 0 new citations.origin/main. None of those commits touchesui/packages/plugin-chatbot/**orpnpm-lock.yaml. The derivation flagged it as STALE TREE.Generated by Claude Code