fix(webui): parse CJK emphasis at delimiter boundaries

This commit is contained in:
chengyongru authored and chengyongru committed 2026-10-22 01:34:19 +08:00
1 parent d5cf09d738
commit 51a0fc83a2
8 files changed
+244 -56

No files matched your search

+3
View File
@@ -23,6 +23,7 @@ import { NewChatSkeletonFixture } from "./new-chat-skeleton-fixture";
import "../src/globals.css";
import { DiagramFixture } from "./diagram-fixture";
import { TypographyFixture } from "./typography-fixture";
import { MarkdownEmphasisFixture } from "./markdown-emphasis-fixture";
import { HistoryBoundaryFixture } from "./history-boundary-fixture";
import { ChatFailureFixture } from "./chat-failure-fixture";
import { ThreadLoadingFixture } from "./thread-loading-fixture";
@@ -175,6 +176,8 @@ createRoot(document.getElementById("root")!).render(<TooltipProvider>
? <SidebarActivityFixture />
: parameters.get("case") === "chat-failure"
? <ChatFailureFixture parameters={parameters} />
: parameters.get("case") === "markdown-emphasis"
? <MarkdownEmphasisFixture />
: parameters.get("case") === "typography"
? <ClientProvider client={railClient} token="fixture"><TypographyFixture /></ClientProvider>
: parameters.get("case") === "history-hydration"
@@ -0,0 +1,21 @@
import { useState } from "react";
import { MarkdownText } from "@/components/MarkdownText";
const source = [
"**`ThreadTranscript` 已经朝这个方向走了一步:它把正文、来源覆盖和分页接纳集中起来,因此可以看作一个隐式的状态转换模型。**但“集中到一个类”不等于已经有清晰的状态机。",
"前文**「重点」**后文。**参考 [说明](https://example.com) 的结论。**继续阅读。",
"**日本語。**続き。**한국어(설명)**입니다。",
"**中文。** 继续。**English.** Next.",
"**边界说明: **issue",
].join("\n\n");
export function MarkdownEmphasisFixture() {
const [end, setEnd] = useState(0);
const [streaming, setStreaming] = useState(true);
return <main className="mx-auto max-w-3xl p-6">
<button onClick={() => setEnd((value) => Math.min(source.length, value + 1))}>Next character</button>
<button onClick={() => { setEnd(source.length); setStreaming(false); }}>Complete</button>
<div data-testid="reply"><MarkdownText streaming={streaming} preserveStreamingLayout>{source.slice(0, end)}</MarkdownText></div>
</main>;
}
+23
View File
@@ -0,0 +1,23 @@
import { expect, test } from "@playwright/test";
for (const width of [390, 1440]) {
test(`CJK emphasis retains inline semantics through completion at ${width}px`, async ({ page }) => {
await page.setViewportSize({ width, height: 900 });
await page.goto("/browser/fixture.html?case=markdown-emphasis");
// Reveal the inline code while its enclosing emphasis is still incomplete.
for (let index = 0; index < 24; index++) {
await page.getByRole("button", { name: "Next character", exact: true }).click();
}
const reply = page.getByTestId("reply");
await expect(reply.locator("code")).toHaveText("ThreadTranscript");
await page.getByRole("button", { name: "Complete", exact: true }).click();
await expect(reply.locator("strong code")).toHaveText("ThreadTranscript");
await expect(reply.locator("strong a")).toHaveText("说明");
await expect(reply.locator("strong a")).toHaveAttribute("href", "https://example.com");
await expect(reply.locator("strong")).toHaveCount(7);
await expect(reply.locator("p").last()).toHaveText("**边界说明: **issue");
await expect(reply.locator("p").first()).toContainText("但“集中到一个类”不等于已经有清晰的状态机。");
await expect(reply.locator("strong").first()).not.toContainText("但“集中到一个类”");
await expect(reply).toBeVisible();
});
}