From 2ea593c2e284c74e419f3875e2e4cbb8c34104d1 Mon Sep 17 00:00:00 2001 From: Michael Grundberg Date: Mon, 30 Nov 2026 13:01:47 +0100 Subject: [PATCH 1/3] fix(web): a markdown table column no longer shrinks to one letter per line Rendered markdown sets `overflow-wrap: anywhere` so that a long path in prose wraps, and table cells inherited it. With `anywhere`, the browser counts every letter as a break point when it computes a cell's minimum width. The header cells never wrap, so in a table whose headers fill the width, the column under an empty header got only its minimum width, and its labels stood one letter per line. Table cells now use `overflow-wrap: break-word`. A cell still breaks a word that is wider than its column, but its minimum width is its longest word. In Chromium, the label column of a five-column table went from 36 px to 74 px and wraps between words. A table with an unbreakable cell wider than the view scrolls sideways inside its wrapper, which the wrapper already allows. The Response Viewer and the File Viewer's markdown view share these rules. Co-Authored-By: Claude Opus 5.5 --- src/web/public/styles.css | 5 +++ test/response-viewer-table-cells.test.ts | 45 ++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 test/response-viewer-table-cells.test.ts diff --git a/src/web/public/styles.css b/src/web/public/styles.css index 990a981e..b2b3a6d8 100644 --- a/src/web/public/styles.css +++ b/src/web/public/styles.css @@ -14119,6 +14119,11 @@ html:is([data-skin="paper-gray"], [data-skin="solarized-light"], [data-skin="cat text-align: start; vertical-align: top; white-space: normal; + /* A cell breaks a word only when the word alone is wider than the column. The `anywhere` + that cells inherit from .rv-text also lets the table count every letter as a break + point when it sizes its columns, so a column beside wide headers shrank to one letter + per line. */ + overflow-wrap: break-word; } .rv-text th:last-child, .rv-text td:last-child, diff --git a/test/response-viewer-table-cells.test.ts b/test/response-viewer-table-cells.test.ts new file mode 100644 index 00000000..b17fb687 --- /dev/null +++ b/test/response-viewer-table-cells.test.ts @@ -0,0 +1,45 @@ +/** + * @fileoverview Table cells in rendered markdown break only words wider than their column + * (src/web/public/styles.css). + * + * Rendered markdown sets `overflow-wrap: anywhere` so that a long path in prose wraps, and + * table cells inherited it. `anywhere` also counts every letter as a break point when the + * browser computes a cell's minimum width, and the header cells never wrap. In a table + * whose headers filled the width, the column under an empty header shrank to one letter per + * line. Cells now use `break-word`, which breaks a word only when it would overflow and + * leaves the minimum width at the longest word. + * + * jsdom has no layout, so this pins the declaration. Chromium was measured on a five-column + * table when the change was made: the label column went from 36 px, one letter per line, to + * 74 px, wrapped between words. + */ +import { readFileSync } from 'node:fs'; +import { resolve } from 'node:path'; +import { describe, expect, it } from 'vitest'; + +const css = readFileSync(resolve(import.meta.dirname, '../src/web/public/styles.css'), 'utf8'); + +/** The declarations of the first rule whose selector list contains `selector`. */ +function ruleBody(selector: string): string { + for (const match of css.matchAll(/([^{}]+)\{([^{}]*)\}/g)) { + const selectors = match[1] + .replace(/\/\*[\s\S]*?\*\//g, '') + .split(',') + .map((s) => s.trim()); + if (selectors.includes(selector)) return match[2].replace(/\/\*[\s\S]*?\*\//g, ''); + } + throw new Error(`no rule for ${selector}`); +} + +describe('rendered markdown table cells', () => { + it('still wraps long words in prose anywhere', () => { + expect(ruleBody('.rv-text')).toMatch(/overflow-wrap:\s*anywhere/); + }); + + it.each(['.rv-text td', '.rv-text th', '.rv-table-wrap td', '.response-viewer-body > table td'])( + '%s breaks a word only when the word overflows', + (selector) => { + expect(ruleBody(selector)).toMatch(/overflow-wrap:\s*break-word/); + } + ); +}); From 5588a54e3fca15a6043964bec2508a21914fa1ff Mon Sep 17 00:00:00 2001 From: Michael Grundberg Date: Mon, 30 Nov 2026 13:50:00 +0100 Subject: [PATCH 2/3] fix(web): a table column of linked paths keeps a readable width The first commit left one case of the same squeeze. Codeman turns the paths in an answer into links, and a linked path keeps `word-break: break-all` so that it can wrap anywhere. That lets the browser count every letter as a break point when it sizes the column, so in a table whose headers fill the width, a column of paths shrank to three or four letters per line. A cell that holds a linked path now has a minimum width of 6em. Other cells keep their natural width, so a narrow column such as row numbers stays narrow. On a 390 px view in Firefox and Chromium, a path column went from 48 px to 83 px, and a `#` column kept its 32 px. The comment on the cell rule also said wrongly that a cell breaks a word wider than its column. In automatic table layout a column is never narrower than its longest word, so that never happens, and the comment now says that. The test reads every rule that names a selector, in styles.css and mobile.css, with comments removed first, so a later override fails it. Co-Authored-By: Claude Opus 5.5 --- src/web/public/styles.css | 14 ++++-- test/response-viewer-table-cells.test.ts | 59 ++++++++++++++++-------- 2 files changed, 49 insertions(+), 24 deletions(-) diff --git a/src/web/public/styles.css b/src/web/public/styles.css index b2b3a6d8..d5a1957d 100644 --- a/src/web/public/styles.css +++ b/src/web/public/styles.css @@ -14119,13 +14119,19 @@ html:is([data-skin="paper-gray"], [data-skin="solarized-light"], [data-skin="cat text-align: start; vertical-align: top; white-space: normal; - /* A cell breaks a word only when the word alone is wider than the column. The `anywhere` - that cells inherit from .rv-text also lets the table count every letter as a break - point when it sizes its columns, so a column beside wide headers shrank to one letter - per line. */ + /* A cell wraps between words, so its column is never narrower than its longest word. + With the `anywhere` that cells inherit from .rv-text, the table counted every letter + as a break point when it sized its columns, and a column beside wide headers shrank + to one letter per line. */ overflow-wrap: break-word; } +/* A linked path keeps `word-break: break-all` (the a.rv-path rule below), which lets its + column shrink the same way. A floor keeps about ten characters of the path per line. */ +.rv-table-wrap td:has(a.rv-path:not(.rv-path-link)) { + min-width: 6em; +} + .rv-text th:last-child, .rv-text td:last-child, .response-viewer-body > table th:last-child, .response-viewer-body > table td:last-child, diff --git a/test/response-viewer-table-cells.test.ts b/test/response-viewer-table-cells.test.ts index b17fb687..166a8023 100644 --- a/test/response-viewer-table-cells.test.ts +++ b/test/response-viewer-table-cells.test.ts @@ -1,45 +1,64 @@ /** - * @fileoverview Table cells in rendered markdown break only words wider than their column + * @fileoverview Table columns in rendered markdown never shrink below a readable width * (src/web/public/styles.css). * * Rendered markdown sets `overflow-wrap: anywhere` so that a long path in prose wraps, and * table cells inherited it. `anywhere` also counts every letter as a break point when the * browser computes a cell's minimum width, and the header cells never wrap. In a table * whose headers filled the width, the column under an empty header shrank to one letter per - * line. Cells now use `break-word`, which breaks a word only when it would overflow and - * leaves the minimum width at the longest word. + * line. Cells now use `break-word`, so a column is never narrower than its longest word. * - * jsdom has no layout, so this pins the declaration. Chromium was measured on a five-column - * table when the change was made: the label column went from 36 px, one letter per line, to - * 74 px, wrapped between words. + * A linkified path (`a.rv-path`) keeps `word-break: break-all`, which has the same effect on + * its column, so a cell that holds one gets a minimum width. + * + * jsdom has no layout, so this pins the declarations. Firefox and Chromium were measured + * when the change was made, on a 390 px view: the label column went from one letter per + * line to whole words, a path column from 48 px to 83 px, and a `#` column kept its 32 px. */ import { readFileSync } from 'node:fs'; import { resolve } from 'node:path'; import { describe, expect, it } from 'vitest'; -const css = readFileSync(resolve(import.meta.dirname, '../src/web/public/styles.css'), 'utf8'); +const publicCss = (name: string) => + readFileSync(resolve(import.meta.dirname, '../src/web/public', name), 'utf8').replace(/\/\*[\s\S]*?\*\//g, ''); -/** The declarations of the first rule whose selector list contains `selector`. */ -function ruleBody(selector: string): string { - for (const match of css.matchAll(/([^{}]+)\{([^{}]*)\}/g)) { - const selectors = match[1] - .replace(/\/\*[\s\S]*?\*\//g, '') - .split(',') - .map((s) => s.trim()); - if (selectors.includes(selector)) return match[2].replace(/\/\*[\s\S]*?\*\//g, ''); +/** Every rule whose selector list contains `selector`, in cascade order across both sheets. */ +function rulesFor(selector: string): string[] { + const bodies: string[] = []; + for (const css of [publicCss('styles.css'), publicCss('mobile.css')]) { + for (const match of css.matchAll(/([^{}]+)\{([^{}]*)\}/g)) { + if (match[1].split(',').some((s) => s.trim() === selector)) bodies.push(match[2]); + } } - throw new Error(`no rule for ${selector}`); + return bodies; +} + +/** The value the last rule naming `selector` gives `property`, or undefined. */ +function lastValue(selector: string, property: string): string | undefined { + let value: string | undefined; + for (const body of rulesFor(selector)) { + for (const decl of body.split(';')) { + const [name, ...rest] = decl.split(':'); + if (name.trim() === property) value = rest.join(':').trim(); + } + } + return value; } describe('rendered markdown table cells', () => { it('still wraps long words in prose anywhere', () => { - expect(ruleBody('.rv-text')).toMatch(/overflow-wrap:\s*anywhere/); + expect(lastValue('.rv-text', 'overflow-wrap')).toBe('anywhere'); }); - it.each(['.rv-text td', '.rv-text th', '.rv-table-wrap td', '.response-viewer-body > table td'])( - '%s breaks a word only when the word overflows', + it.each(['.rv-text td', '.rv-text th', '.rv-table-wrap td', '.rv-table-wrap th'])( + '%s wraps between words, so its column is never narrower than its longest word', (selector) => { - expect(ruleBody(selector)).toMatch(/overflow-wrap:\s*break-word/); + expect(lastValue(selector, 'overflow-wrap')).toBe('break-word'); } ); + + it('gives a cell holding a linked path a minimum width, since the path breaks anywhere', () => { + expect(lastValue('.rv-text a.rv-path', 'word-break')).toBe('break-all'); + expect(lastValue('.rv-table-wrap td:has(a.rv-path:not(.rv-path-link))', 'min-width')).toBe('6em'); + }); }); From 691ea6c87a56b3014811a49d80524c5138467aea Mon Sep 17 00:00:00 2001 From: Michael Grundberg Date: Mon, 30 Nov 2026 15:37:05 +0100 Subject: [PATCH 3/3] fix(web): inline code and links in a table cell break anywhere Chromium never breaks a line after `/`, so under the cells' `break-word` a URL, an identifier or a hash in backticks set its column's width, and the whole table scrolled sideways on a phone. Inline code and links in a cell now break anywhere, and a cell holding one gets the 6em floor that cells with a linked path had. In a 360 px column in Chromium and Firefox, URL, identifier and hash tables fit as they did on master. Two costs remain. A code-only column such as `-v` grows from 52 px to 80 px. CSS cannot tell an autolink from a link with a prose label, so a long word in a label can break mid-word in a narrow column. The test's selector lookup now splits a selector list only on commas outside parentheses, so it can find the `:is()` and `:has()` rules. Co-Authored-By: Claude Opus 5.5 --- src/web/public/styles.css | 17 +++++++++-- test/response-viewer-table-cells.test.ts | 36 +++++++++++++++++++----- 2 files changed, 43 insertions(+), 10 deletions(-) diff --git a/src/web/public/styles.css b/src/web/public/styles.css index d5a1957d..ffabfddb 100644 --- a/src/web/public/styles.css +++ b/src/web/public/styles.css @@ -14126,9 +14126,20 @@ html:is([data-skin="paper-gray"], [data-skin="solarized-light"], [data-skin="cat overflow-wrap: break-word; } -/* A linked path keeps `word-break: break-all` (the a.rv-path rule below), which lets its - column shrink the same way. A floor keeps about ten characters of the path per line. */ -.rv-table-wrap td:has(a.rv-path:not(.rv-path-link)) { +/* Inline code and links hold long tokens such as URLs, identifiers and hashes. Chromium + finds no break point inside one, since it never breaks after `/`. Under `break-word` + the longest token set its column's width and the whole table scrolled sideways, so + these tokens break anywhere. A linked path already does, through the `break-all` of + the a.rv-path rule above. CSS cannot tell an autolink from a link with a prose label, + so a label breaks anywhere too. The one exception is a path link's label + (.rv-path-link), which keeps breaking between words. */ +.rv-table-wrap td :is(code, a:not(.rv-path-link)) { + overflow-wrap: anywhere; +} + +/* Breaking anywhere lets a column shrink to one letter per line, so a cell holding such + a token gets a floor of about ten characters. */ +.rv-table-wrap td:has(code, a:not(.rv-path-link)) { min-width: 6em; } diff --git a/test/response-viewer-table-cells.test.ts b/test/response-viewer-table-cells.test.ts index 166a8023..f7a01798 100644 --- a/test/response-viewer-table-cells.test.ts +++ b/test/response-viewer-table-cells.test.ts @@ -8,12 +8,16 @@ * whose headers filled the width, the column under an empty header shrank to one letter per * line. Cells now use `break-word`, so a column is never narrower than its longest word. * - * A linkified path (`a.rv-path`) keeps `word-break: break-all`, which has the same effect on - * its column, so a cell that holds one gets a minimum width. + * Under `break-word`, a token with no break point sets its column's width. Chromium never + * breaks after `/`, so a URL, an identifier or a hash in backticks made the whole table + * scroll sideways on a phone. Inline code and links in a cell therefore break anywhere, + * like a linkified path (`a.rv-path`, `word-break: break-all`) always did. That lets their + * column shrink the same way, so a cell holding one gets a minimum width. * * jsdom has no layout, so this pins the declarations. Firefox and Chromium were measured - * when the change was made, on a 390 px view: the label column went from one letter per - * line to whole words, a path column from 48 px to 83 px, and a `#` column kept its 32 px. + * when the change was made, in a 360 px column: URL, identifier and hash tables fit as they + * did on master, a path column went from 48 px to 80 px, and a `-v` column from 52 px to + * 80 px. */ import { readFileSync } from 'node:fs'; import { resolve } from 'node:path'; @@ -22,12 +26,29 @@ import { describe, expect, it } from 'vitest'; const publicCss = (name: string) => readFileSync(resolve(import.meta.dirname, '../src/web/public', name), 'utf8').replace(/\/\*[\s\S]*?\*\//g, ''); +/** The selectors of a rule, split on the commas outside `:is()`, `:has()` and `:not()`. */ +function selectorList(prelude: string): string[] { + const parts: string[] = []; + let depth = 0; + let start = 0; + for (let i = 0; i < prelude.length; i++) { + if (prelude[i] === '(') depth++; + else if (prelude[i] === ')') depth--; + else if (prelude[i] === ',' && depth === 0) { + parts.push(prelude.slice(start, i).trim()); + start = i + 1; + } + } + parts.push(prelude.slice(start).trim()); + return parts; +} + /** Every rule whose selector list contains `selector`, in cascade order across both sheets. */ function rulesFor(selector: string): string[] { const bodies: string[] = []; for (const css of [publicCss('styles.css'), publicCss('mobile.css')]) { for (const match of css.matchAll(/([^{}]+)\{([^{}]*)\}/g)) { - if (match[1].split(',').some((s) => s.trim() === selector)) bodies.push(match[2]); + if (selectorList(match[1]).includes(selector)) bodies.push(match[2]); } } return bodies; @@ -57,8 +78,9 @@ describe('rendered markdown table cells', () => { } ); - it('gives a cell holding a linked path a minimum width, since the path breaks anywhere', () => { + it('breaks inline code and links in a cell anywhere, and gives their cell a minimum width', () => { expect(lastValue('.rv-text a.rv-path', 'word-break')).toBe('break-all'); - expect(lastValue('.rv-table-wrap td:has(a.rv-path:not(.rv-path-link))', 'min-width')).toBe('6em'); + expect(lastValue('.rv-table-wrap td :is(code, a:not(.rv-path-link))', 'overflow-wrap')).toBe('anywhere'); + expect(lastValue('.rv-table-wrap td:has(code, a:not(.rv-path-link))', 'min-width')).toBe('6em'); }); });