Skip to content

Commit 23d61fa

Browse files
fix(plugin-markdown): bold ending in full-width punctuation renders bold before a CJK letter (#36968)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} --> _Requested by **Yibo Wang** · [project thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBDHJBvzScLgkhKgms97sNuU)_ repo:objectstack#3 · os-support-ai · session_01WGufzhoBbwh8URjwQHde8v Fixes #36946 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:控制台帮助手册里,中文粗体以全角标点()。:结尾、后面紧跟中文字时,不再显示成带星号的原文,而是正常加粗;英文手册与聊天不变。 - 为什么做:聊天里同样的问题上周已修好,手册阅读器走的是另一条渲染链没跟上;这次让两处用同一条中日韩强调规则,HotCRM 中文手册里 17 处受影响的句子随之恢复。 - 出错会怎样:只影响手册正文的粗体与斜体识别,安全过滤照旧;若有误判,读者看到的是粗体范围不对,可直接撤回本改动。 - 要你做什么:无。 ## What changes - **Measured first: the manual reader renders through `@object-ui/plugin-markdown`.** The docs page (`ui/apps/console/src/pages/DocPage.tsx`) draws the article body with `MarkdownRenderer` from `@object-ui/plugin-markdown`, which lazy-loads `MarkdownImpl`. Its remark chain was `[remarkGfm, remarkAlert]`, so the card's premise holds. - `MarkdownImpl.tsx` now runs `remark-cjk-friendly/parseOnly` first: `[remarkCjkFriendly, remarkGfm, remarkAlert]`. This is the rule the chat surface already runs. It goes first, as in chat's `remarkPluginsBefore` slot, so it owns the emphasis (attention) tokenizer. `parseOnly` because this renderer never serializes markdown, the reason chat's docblock gives. - `@object-ui/plugin-markdown` adds the dependency `remark-cjk-friendly` at `^2.3.4`, the same range plugin-chatbot pins. The lockfile gains one importer entry and no new package: the version resolves to the snapshot plugin-chatbot already uses. - **One rule, two import sites, chosen on purpose.** plugin-chatbot does not depend on plugin-markdown, and plugin-markdown does not depend on plugin-chatbot (both depend only on `components`/`core`/`types`, plus `i18n`/`react` for chatbot). One shared exported helper would mean a new cross-package dependency: chatbot pulling in mermaid and the rehype chain, or markdown pulling in streamdown. The config shapes also differ (a streamdown `PluginConfig` against react-markdown `remarkPlugins`). So each package imports the plugin once, and each site's comment names the other. `chatMarkdownPlugins.ts` changes a comment only. - **The sanitize schema is not widened.** The plugin swaps the micromark attention construct and nothing else, so it can only produce mdast `strong`/`emphasis` nodes. Those become the `strong`/`em` elements the default schema already allows, and `rehypeSanitize` still runs last in the rehype chain. A pin shows the rendered tag set for a CJK bold line is exactly `div`, `p`, `strong`. A second pin shows raw HTML with an event handler, and a `javascript:` link, stay stripped inside a CJK bold run. - One changeset (`.changeset/36946-manual-reader-cjk-bold.md`), patch, lists both published packages the diff touches: `@object-ui/plugin-markdown` (the fix) and `@object-ui/plugin-chatbot` (comment only). **Read first, by risk:** 1. `ui/packages/plugin-markdown/src/MarkdownImpl.tsx`: the `remarkPlugins` line and its comment block. This is the only behaviour change. 2. `ui/packages/plugin-markdown/src/markdown-render.test.tsx`: the new `bold next to CJK full-width punctuation` describe. 3. `pnpm-lock.yaml`: add-only, one importer entry. **Two-minute verification:** `pnpm --dir ui exec vitest run packages/plugin-markdown/src/markdown-render.test.tsx`. Expect 24 passed. With the plugin removed from `remarkPlugins`, 7 of them go red, as the ablation below shows. ## Tests Tests: `@object-ui/plugin-markdown` `test` (6 files, 63 tests) and `type-check` (`tsc --noEmit && tsc -p tsconfig.test.json`), plus `pnpm --dir ui exec vitest run scripts/`, all run on the final head `f0a46f212cf`. New pins, as a top-level describe in the package's existing render harness: - `**关闭日期**和**解决耗时(小时)**会被清空` renders both runs as strong (the card's main repro, from `crm_service_cases.zh.md`). - `- **每个项目一张报销单。**每个项目的费用` renders strong (full-width full stop). - `**它跳过和拒绝什么:**已经在活动中的人` renders strong (full-width colon). - `**投资回报率(%)**是(收入 − 成本)` renders strong. - Sanitizer: the rendered tag set is exactly `div`/`p`/`strong`. An event-handler attribute and a `javascript:` link stay stripped inside a CJK bold run. - English controls, unchanged: `a **bold** word` and `foo**bar**baz` are bold. A closer after whitespace, a code span and backslash escapes stay literal with no `strong`. - Composition: a CJK bold run inside a `> [!NOTE]` alert keeps the `markdown-alert-note` callout, and one inside a GFM table cell keeps the `table`. Both render strong. <details><summary>Red on the base, green with the fix</summary> Before the fix, on `62692b7f8b3` with only the test file added: ``` × a closer after a full-width parenthesis, before a CJK letter renders strong × a closer after a full-width full stop, before a CJK letter renders strong × a closer after a full-width colon, before a CJK letter renders strong × a closer after a full-width parenthesis holding a percent sign renders strong × adds no element the sanitizer did not already allow × keeps raw HTML and javascript: links stripped inside a CJK bold run × still renders a CJK bold run inside an alert and a GFM table Tests 7 failed | 17 passed (24) ``` The fix, on `f0a46f212cf`: ``` > vitest run --root ../.. packages/plugin-markdown/ Test Files 6 passed (6) Tests 63 passed (63) > tsc --noEmit && tsc -p tsconfig.test.json os-verify-lock: VERDICT command-exit 0 ``` </details> <details><summary>Ablation (scripts/ablation-replace.mjs, then restored)</summary> The test imports `./MarkdownImpl` from source, so there is no dist hop to rebuild. ``` ablation-replace: anchor "const remarkPlugins = [remarkCjkFriendly, remarkGfm, remarkAlert]" x1 (before) ablation-replace: ok mutation landed: anchor 1 -> 0, blob 2e6b55a -> 860686304aa7 Tests 7 failed | 17 passed (24) ablation-replace: command exited 1 ablation-replace: blob after restore 2e6b55a ablation-replace: blob at HEAD 2e6b55a ablation-replace: ok restored: blob == HEAD (2e6b55a) and `git diff HEAD` is empty ``` The same 7 go red, and the 17 controls stay green. </details> ## Acceptance notes - **The MCP `read_package_doc` / `search_package_docs` (card's last line) do not render markdown.** `packages/runtime/src/domains/mcp-package-docs.ts` returns the doc's `content` verbatim (served locale or translation) and excerpts the raw source for search hits. No emphasis parse runs there, so the CJK flanking rule does not apply. The reading client parses the markdown itself. Not changed. - GFM strikethrough (`~~`) beside full-width punctuation is outside `remark-cjk-friendly` by its own README, which points to a sibling `remark-cjk-friendly-gfm-strikethrough` package. Chat has the same scope. Not measured on any shipped manual: no reproduction, so no card. Follow-up: none. - `@object-ui/plugin-markdown` builds with every bare import external, so `dist/index.js` imports `remark-cjk-friendly/parseOnly` and resolves it through the new dependency. The console already bundles the same version for chat. - Local verification is scoped to the derived gate list (below). The branch is not merged with the newer `origin/main`. `overlap-check` reports clean merges with `origin/main` and with the three open PRs that share a file (#36845, #35129, #34223). ## Verification <details><summary>Derived gate families (dispatch-gates, 60 derived: 59 run, 1 NOT MEASURED, 0 UNRUN)</summary> `node scripts/pm/dispatch-gates.mjs --repo objectstack-ai/objectstack --ran ran.list` gives `✓ dispatch-gates --ran: 60 derived famil(ies) accounted for — 59 run, 1 NOT-MEASURED`. The derivation names the tree `objectstack-ai/objectstack` at `f0a46f212cf`. - 58 families exit 0, `pnpm --dir ui exec vitest run scripts/` among them (`Test Files 172 passed | 2 skipped`, `Tests 5126 passed | 2 skipped`). Exit codes were captured before any pipe. - NOT MEASURED: `pnpm check:dual-build-cjs-loads`, reason: its self-test passes (94 cases), but the scan answers `PREREQUISITE NOT MET` (exit 3). It reads every `@objectstack/*` package's `dist`, and this worktree built only the plugin-markdown closure. CI `Lint & Repo Gates` runs it. - `node scripts/pm/overlap-check.mjs` before the push: `VERDICT clean exit 0`. </details> `@object-ui/plugin-chatbot` is not tested locally: its diff is a comment only. CI `Test UI` and `Type Check UI` run it. 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- signed: repo:objectstack#3 · os-support-ai · session_01WGufzhoBbwh8URjwQHde8v --> Co-authored-by: Claude <noreply@anthropic.com>
1 parent 7c9b22b commit 23d61fa

6 files changed

Lines changed: 114 additions & 1 deletion

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
'@object-ui/plugin-markdown': patch
3+
'@object-ui/plugin-chatbot': patch
4+
---
5+
6+
fix(plugin-markdown): bold that ends in full-width punctuation renders bold before a CJK letter
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
The markdown renderer the console's manual reader uses (`@object-ui/plugin-markdown`) left a `**bold**` run as literal asterisks when the run ended in full-width punctuation and a CJK letter followed it, as in `**解决耗时(小时)**会被清空`, `**每个项目一张报销单。**每个项目` or `**它跳过和拒绝什么:**已经`. CommonMark counts full-width punctuation as punctuation, so such a closer is not right-flanking; a Chinese or Japanese sentence puts no space there.
12+
13+
The renderer now runs `remark-cjk-friendly` (its `parseOnly` entry, a new MIT dependency at `^2.3.4`) ahead of remark-gfm, the rule the chat surface already runs. It reads a CJK character beside a `**` run the way it reads the whitespace an English sentence would have there. ASCII emphasis, code spans, backslash escapes, GFM tables and GitHub-style alerts render as before, and the output still passes the same sanitize schema.
14+
15+
`@object-ui/plugin-chatbot` changes a comment only: its CJK rule now names the renderer's copy, since neither package depends on the other and each imports the plugin itself. No props or exports change in either package; nothing to migrate.

‎pnpm-lock.yaml‎

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎ui/packages/plugin-chatbot/src/chatMarkdownPlugins.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ import type { CjkPlugin, PluginConfig } from "streamdown";
2626
* the emphasis tokenizer; ASCII emphasis, code spans and backslash escapes
2727
* keep their CommonMark meaning. The `parseOnly` entry leaves out the
2828
* markdown serializer half, which the chat never runs.
29+
*
30+
* The manual reader carries the same rule in `@object-ui/plugin-markdown`
31+
* (`src/MarkdownImpl.tsx`, its react-markdown `remarkPlugins`). Neither
32+
* package depends on the other, so each imports the plugin itself; change the
33+
* two together.
2934
*/
3035
const CJK_EMPHASIS: CjkPlugin = {
3136
name: "cjk",

‎ui/packages/plugin-markdown/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"rehype-highlight": "^7.0.2",
4747
"rehype-sanitize": "^6.0.0",
4848
"rehype-slug": "^6.0.0",
49+
"remark-cjk-friendly": "^2.3.4",
4950
"remark-gfm": "^4.0.1",
5051
"remark-github-blockquote-alert": "^2.1.0"
5152
},

‎ui/packages/plugin-markdown/src/MarkdownImpl.tsx‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import * as React from "react"
1010
import ReactMarkdown, { type Components } from "react-markdown"
11+
import remarkCjkFriendly from "remark-cjk-friendly/parseOnly"
1112
import remarkGfm from "remark-gfm"
1213
import { remarkAlert } from "remark-github-blockquote-alert"
1314
import rehypeSanitize, { defaultSchema } from "rehype-sanitize"
@@ -95,7 +96,29 @@ function rehypeNormalizeClassName() {
9596
return (tree: unknown) => visit(tree as { children?: unknown[] })
9697
}
9798

98-
const remarkPlugins = [remarkGfm, remarkAlert]
99+
// ─── Emphasis next to CJK full-width punctuation ────────────────────────
100+
//
101+
// CommonMark decides whether a `**` run can open or close emphasis from the
102+
// characters on either side, and counts full-width punctuation ()。:,、
103+
// 《》「」) as punctuation. A Chinese or Japanese sentence puts no space beside
104+
// the run, so `**解决耗时(小时)**会被清空` (punctuation before the closer, a
105+
// CJK letter after it) is not right-flanking and stays literal asterisks.
106+
//
107+
// `remark-cjk-friendly` replaces the attention tokenizer with the
108+
// markdown-cjk-friendly rule, which reads a CJK character beside the run the
109+
// way it reads the whitespace an English sentence would have there. It is
110+
// listed first, ahead of remark-gfm, so it owns the emphasis tokenizer; ASCII
111+
// emphasis, code spans and backslash escapes keep their CommonMark meaning.
112+
// It changes how `*`/`_` runs tokenize and nothing else, so its output is the
113+
// same `strong`/`emphasis` nodes rehype-sanitize already allows. The
114+
// `parseOnly` entry leaves out the markdown serializer half, which this
115+
// renderer never runs.
116+
//
117+
// The chat surface carries the same rule in
118+
// `@object-ui/plugin-chatbot` (`src/chatMarkdownPlugins.ts`, a streamdown
119+
// PluginConfig). Neither package depends on the other, so each imports the
120+
// plugin itself; change the two together.
121+
const remarkPlugins = [remarkCjkFriendly, remarkGfm, remarkAlert]
99122
const rehypePlugins = [
100123
rehypeSlug,
101124
rehypeNormalizeClassName,

‎ui/packages/plugin-markdown/src/markdown-render.test.tsx‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,69 @@ describe('mermaid diagrams (ADR-0046)', () => {
9696
expect(html).toContain('hljs');
9797
});
9898
});
99+
100+
/**
101+
* Bold that ends in full-width punctuation, followed directly by a CJK letter.
102+
*
103+
* CommonMark counts full-width punctuation ()。:) as punctuation, so a
104+
* closing `**` with that punctuation before it and a CJK letter after it is
105+
* not right-flanking, and the run stays literal asterisks. A Chinese or
106+
* Japanese sentence puts no space there. The manual reader renders package
107+
* docs through this pipeline, so the sources below are lines from shipped
108+
* zh-CN manuals. The chat surface carries the same rule
109+
* (`plugin-chatbot/src/chatMarkdownPlugins.ts`).
110+
*/
111+
describe('bold next to CJK full-width punctuation', () => {
112+
/** Every element tag name in the rendered markup, deduplicated. */
113+
const tagNames = (html: string): string[] =>
114+
[...new Set([...html.matchAll(/<([a-z][a-z0-9]*)\b/g)].map((m) => m[1]))].sort();
115+
116+
it.each([
117+
['a closer after a full-width parenthesis, before a CJK letter', '**关闭日期**和**解决耗时(小时)**会被清空', ['关闭日期', '解决耗时(小时)']],
118+
['a closer after a full-width full stop, before a CJK letter', '- **每个项目一张报销单。**每个项目的费用', ['每个项目一张报销单。']],
119+
['a closer after a full-width colon, before a CJK letter', '**它跳过和拒绝什么:**已经在活动中的人', ['它跳过和拒绝什么:']],
120+
['a closer after a full-width parenthesis holding a percent sign', '**投资回报率(%)**是(收入 − 成本)', ['投资回报率(%)']],
121+
])('%s renders strong', (_label, md, bold) => {
122+
const html = render(md);
123+
for (const text of bold) expect(html).toContain(`<strong>${text}</strong>`);
124+
expect(html).not.toContain('**');
125+
});
126+
127+
it('adds no element the sanitizer did not already allow', () => {
128+
const html = render('**解决耗时(小时)**会被清空');
129+
expect(tagNames(html)).toEqual(['div', 'p', 'strong']);
130+
});
131+
132+
it('keeps raw HTML and javascript: links stripped inside a CJK bold run', () => {
133+
const html = render('**<img src=x onerror="alert(1)">(小时)**会被清空,**[链接](javascript:alert(1))。**然后');
134+
expect(html).not.toContain('onerror');
135+
expect(html).not.toContain('javascript:');
136+
expect(html).not.toContain('**');
137+
});
138+
139+
it.each([
140+
['plain English bold', 'a **bold** word', '<strong>bold</strong>'],
141+
['intraword ASCII bold', 'foo**bar**baz', 'foo<strong>bar</strong>baz'],
142+
])('leaves %s as CommonMark has it', (_label, md, expected) => {
143+
expect(render(md)).toContain(expected);
144+
});
145+
146+
it.each([
147+
['a closer after whitespace', '**not bold **here', '**not bold **here'],
148+
['a code span', '`**x**`', '<code>**x**</code>'],
149+
['backslash escapes', '\\*\\*x\\*\\*', '**x**'],
150+
])('keeps %s literal, as CommonMark has it', (_label, md, expected) => {
151+
const html = render(md);
152+
expect(html).toContain(expected);
153+
expect(html).not.toContain('<strong>');
154+
});
155+
156+
it('still renders a CJK bold run inside an alert and a GFM table', () => {
157+
const alert = render('> [!NOTE]\n> **解决耗时(小时)**会被清空\n');
158+
expect(alert).toMatch(/class="[^"]*markdown-alert[^"]*markdown-alert-note/);
159+
expect(alert).toContain('<strong>解决耗时(小时)</strong>');
160+
const table = render('| 字段 | 说明 |\n|---|---|\n| 耗时 | **解决耗时(小时)**会被清空 |\n');
161+
expect(table).toContain('<table');
162+
expect(table).toContain('<strong>解决耗时(小时)</strong>');
163+
});
164+
});

0 commit comments

Comments
 (0)