diff --git a/webui/browser/typography-fixture.tsx b/webui/browser/typography-fixture.tsx index fae612633..f36f4cc46 100644 --- a/webui/browser/typography-fixture.tsx +++ b/webui/browser/typography-fixture.tsx @@ -41,6 +41,10 @@ const content = `# 阅读,让思路自然延续 | 标题 Heading | 清楚的内容层级 | 保留结构,而非所有文字同大 | | Code | configuration.readingTextSize | 完整显示,必要时在局部滚动 | +| $T$ | $q-p$ | 实测梯度 $\\frac{1}{T}(q-p)$ | 式(4)预测 $\\frac{\\delta}{NT^2}$ | +| --- | --- | --- | --- | +| 1 | $[0.0208,\\ -0.0179,\\ -0.0031]$ | $[1.45,-0.52,-0.93]\\times10^{-3}$ | $[1.33,-0.33,-1.00]\\times10^{-3}$ | + \`\`\`typescript // 中文注释与 English code const preference = { readingTextSize: "standard" }; diff --git a/webui/browser/typography.spec.ts b/webui/browser/typography.spec.ts index 2ddf65a6c..900c777f0 100644 --- a/webui/browser/typography.spec.ts +++ b/webui/browser/typography.spec.ts @@ -33,6 +33,11 @@ for (const narrow of [false, true]) { await expect(group.getByRole("radio", { name: "阅读字号:标准", exact: true })).toBeChecked(); await expect(group.getByRole("radio")).toHaveCount(3); const stable = await metrics(page.locator(".settings-row").first().locator(".text-control-label")); + const tables = page.getByTestId("markdown-data-table"); + const formulaTable = tables.last(); + await expect(tables).toHaveCount(2); + await expect(formulaTable.locator(".katex")).toHaveCount(7); + await page.evaluate(() => document.fonts.ready); const observations = []; for (const [size, label, bodySize] of [ ["small", "阅读字号:小", narrow ? 15 : 16], @@ -59,6 +64,26 @@ for (const narrow of [false, true]) { for (const selector of ["table", "th", "td"]) { expect((await metrics(page.locator(`.markdown-content ${selector}`).first())).size).toBeCloseTo(bodySize * 0.875); } + expect(await tables.first().evaluate(node => node.scrollWidth <= node.clientWidth + 1)).toBe(true); + await expect.poll(() => formulaTable.locator(".katex-html > .base").evaluateAll((nodes) => nodes.every((node) => { + const formula = node.getBoundingClientRect(); + const cell = node.closest("th, td")!; + const bounds = cell.getBoundingClientRect(); + const style = getComputedStyle(cell); + return formula.width > 0 + && formula.left >= bounds.left + parseFloat(style.paddingLeft) - 1 + && formula.right <= bounds.right - parseFloat(style.paddingRight) + 1; + }))).toBe(true); + if (narrow) { + expect(await formulaTable.evaluate(node => node.scrollWidth > node.clientWidth)).toBe(true); + await formulaTable.evaluate(node => { node.scrollLeft = node.scrollWidth; }); + await expect.poll(() => formulaTable.evaluate((node) => { + const bounds = node.getBoundingClientRect(); + const lastCell = node.querySelector("tbody td:last-child")!.getBoundingClientRect(); + return lastCell.left >= bounds.left - 1 && lastCell.right <= bounds.right + 1; + })).toBe(true); + await formulaTable.evaluate(node => { node.scrollLeft = 0; }); + } expect((await metrics(page.locator(".code-content pre"))).size).toBeCloseTo(bodySize * 0.875); expect((await metrics(page.locator(".markdown-inline-code"))).size).toBeCloseTo(bodySize * 0.875); expect((await metrics(page.locator("textarea"))).size).toBe(Math.max(16, bodySize)); diff --git a/webui/src/components/MarkdownTextRenderer.tsx b/webui/src/components/MarkdownTextRenderer.tsx index 9e88aca27..7d86871e3 100644 --- a/webui/src/components/MarkdownTextRenderer.tsx +++ b/webui/src/components/MarkdownTextRenderer.tsx @@ -699,7 +699,7 @@ export default function MarkdownTextRenderer({ >