Skip to content

Commit 5900498

Browse files
fix(ui): keep chat Markdown block rhythm consistent
Fixes #122269
1 parent edb7a16 commit 5900498

2 files changed

Lines changed: 67 additions & 19 deletions

File tree

‎ui/src/e2e/route-css.e2e.test.ts‎

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,19 +132,41 @@ suite.define(() => {
132132
probe.className = "chat-text";
133133
probe.style.width = "900px";
134134
probe.innerHTML = `
135+
<ol class="probe-list"><li>First</li></ol>
136+
<blockquote class="probe-quote"><p>Quoted block</p></blockquote>
135137
<table>
136138
<thead><tr><th>Dimension</th><th>Sentiment signal</th></tr></thead>
137139
<tbody><tr><td>Demographics</td><td>Experience-dependent sentiment.</td></tr></tbody>
138140
</table>
139-
<ol><li>One central pattern</li><li>Another central pattern</li></ol>
140-
<p><strong>Overall characterization:</strong> Pragmatic adoption under suspicion.</p>
141+
<p class="probe-table-copy"><strong>Overall characterization:</strong> Pragmatic adoption under suspicion.</p>
142+
<ul class="probe-task-list"><li class="task-list-item"><input class="task-list-item-checkbox" type="checkbox" disabled /> Task</li></ul>
143+
<details class="probe-details"><summary>More details</summary><p>Body</p></details>
144+
<ul class="probe-unordered"><li>Unordered</li></ul>
145+
<ol class="probe-ordered"><li>Ordered</li></ol>
141146
`;
142147
document.body.append(probe);
148+
const list = probe.querySelector(".probe-list");
149+
const quote = probe.querySelector(".probe-quote");
143150
const dimension = probe.querySelector("th:first-child");
144151
const demographics = probe.querySelector("td:first-child");
145-
const list = probe.querySelector("ol");
146-
const summary = probe.querySelector("ol + p");
147-
if (!dimension || !demographics || !list || !summary) {
152+
const table = probe.querySelector("table");
153+
const tableCopy = probe.querySelector(".probe-table-copy");
154+
const taskList = probe.querySelector(".probe-task-list");
155+
const details = probe.querySelector(".probe-details");
156+
const unordered = probe.querySelector(".probe-unordered");
157+
const ordered = probe.querySelector(".probe-ordered");
158+
if (
159+
!dimension ||
160+
!demographics ||
161+
!list ||
162+
!quote ||
163+
!table ||
164+
!tableCopy ||
165+
!taskList ||
166+
!details ||
167+
!unordered ||
168+
!ordered
169+
) {
148170
throw new Error("Chat Markdown style probe did not render");
149171
}
150172
const lineCount = (element: Element) => {
@@ -156,18 +178,42 @@ suite.define(() => {
156178
demographicsLineCount: lineCount(demographics),
157179
dimensionLineCount: lineCount(dimension),
158180
firstColumnWidth: dimension.getBoundingClientRect().width,
159-
postListGap: summary.getBoundingClientRect().top - list.getBoundingClientRect().bottom,
160-
postListMargin: Number.parseFloat(getComputedStyle(summary).marginTop),
161-
summaryFontSize: Number.parseFloat(getComputedStyle(summary).fontSize),
181+
listToQuoteGap: quote.getBoundingClientRect().top - list.getBoundingClientRect().bottom,
182+
quoteMargin: Number.parseFloat(getComputedStyle(quote).marginTop),
183+
tableToCopyGap:
184+
tableCopy.getBoundingClientRect().top - table.getBoundingClientRect().bottom,
185+
tableCopyMargin: Number.parseFloat(getComputedStyle(tableCopy).marginTop),
186+
taskListToDetailsGap:
187+
details.getBoundingClientRect().top - taskList.getBoundingClientRect().bottom,
188+
detailsMargin: Number.parseFloat(getComputedStyle(details).marginTop),
189+
unorderedToOrderedGap:
190+
ordered.getBoundingClientRect().top - unordered.getBoundingClientRect().bottom,
191+
orderedMargin: Number.parseFloat(getComputedStyle(ordered).marginTop),
192+
blockFontSize: Number.parseFloat(getComputedStyle(tableCopy).fontSize),
162193
};
163194
probe.remove();
164195
return result;
165196
});
166197
expect(chatMarkdownStyles.dimensionLineCount).toBe(1);
167198
expect(chatMarkdownStyles.demographicsLineCount).toBe(1);
168199
expect(chatMarkdownStyles.firstColumnWidth).toBeGreaterThanOrEqual(128);
169-
expect(chatMarkdownStyles.postListGap).toBeGreaterThan(0);
170-
expect(chatMarkdownStyles.postListMargin / chatMarkdownStyles.summaryFontSize).toBeCloseTo(
200+
expect(chatMarkdownStyles.listToQuoteGap).toBeGreaterThan(0);
201+
expect(chatMarkdownStyles.tableToCopyGap).toBeGreaterThan(0);
202+
expect(chatMarkdownStyles.taskListToDetailsGap).toBeGreaterThan(0);
203+
expect(chatMarkdownStyles.unorderedToOrderedGap).toBeGreaterThan(0);
204+
expect(chatMarkdownStyles.quoteMargin / chatMarkdownStyles.blockFontSize).toBeCloseTo(
205+
0.75,
206+
2,
207+
);
208+
expect(chatMarkdownStyles.tableCopyMargin / chatMarkdownStyles.blockFontSize).toBeCloseTo(
209+
0.75,
210+
2,
211+
);
212+
expect(chatMarkdownStyles.detailsMargin / chatMarkdownStyles.blockFontSize).toBeCloseTo(
213+
0.75,
214+
2,
215+
);
216+
expect(chatMarkdownStyles.orderedMargin / chatMarkdownStyles.blockFontSize).toBeCloseTo(
171217
0.75,
172218
2,
173219
);

‎ui/src/styles/chat/text.css‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,20 @@
5757
outline-offset: 2px;
5858
}
5959

60-
.chat-text :where(p, ul, ol, pre, blockquote, table) {
60+
.chat-text :where(p, ul, ol, pre, blockquote, table, details) {
6161
margin: 0;
6262
}
6363

64-
/* Tables always carry top margin (not just after paragraphs); see the sibling
65-
:where(p + ...) spacing rule below which intentionally omits table. */
64+
/* Keep every adjacent top-level Markdown block on the same rhythm, including
65+
special blocks that otherwise read as part of the preceding block. */
66+
.chat-text
67+
:where(p, ul, ol, pre, blockquote, table, details)
68+
+ :where(p, ul, ol, pre, blockquote, table, details) {
69+
margin-top: 0.75em;
70+
}
71+
72+
/* Tables retain top margin even when first; the adjacent-block rule above gives
73+
tables the same rhythm when they follow another Markdown block. */
6674
.chat-text :where(table) {
6775
margin-top: 0.75em;
6876
border: 1px solid color-mix(in srgb, var(--accent) 20%, var(--border));
@@ -379,12 +387,6 @@
379387
background: rgba(255, 255, 255, 0.04);
380388
}
381389

382-
/* Order contract: stays below the nested-blockquote margin rule so a nested
383-
quote that follows a paragraph gets paragraph rhythm, not the 8px gap. */
384-
.chat-text :where(p + p, p + ul, p + ol, p + pre, p + blockquote, ul + p, ol + p) {
385-
margin-top: 0.75em;
386-
}
387-
388390
:root[data-theme-mode="light"] .chat-text :where(blockquote) {
389391
background: rgba(0, 0, 0, 0.03);
390392
}

0 commit comments

Comments
 (0)