Open History to see the last commit
1/**
2 * Detects markdown that the JS renderer draws as a standalone block View
3 * wrapping a horizontal ScrollView — fenced code blocks and GFM tables.
4 *
5 * Those blocks report an intrinsic width equal to their widest line, which is
6 * effectively unbounded. A user bubble sizes itself from its content
7 * (`maxWidth` with no `width`), so Android lays the bubble's children out
8 * during the unclamped intrinsic pass — where the surrounding paragraphs
9 * collapse to a single line — and never repositions them once the width is
10 * clamped back to `maxWidth`. The result is siblings drawn on top of each
11 * other inside an over-tall bubble. Pinning the bubble's width removes the
12 * intrinsic pass entirely, which is the same reason review-comment bubbles
13 * already carry an explicit width.
14 *
15 * Indented (four-space) code blocks are deliberately not detected: they are
16 * vanishingly rare in chat input and the check would fire on ordinary nested
17 * list continuations.
18 */
19
20const FENCED_CODE_BLOCK = /^ {0,3}(?:```|~~~)/m;
21
22function isTableDelimiterRow(line: string): boolean {
23 const trimmed = line.trim();
24 if (!trimmed.includes("|") || !trimmed.includes("-")) {
25 return false;
26 }
27 return /^[|\-: \t]+$/.test(trimmed);
28}
29
30export function hasWideMarkdownBlock(text: string): boolean {
31 if (FENCED_CODE_BLOCK.test(text)) {
32 return true;
33 }
34 if (!text.includes("|")) {
35 return false;
36 }
37 return text.split("\n").some(isTableDelimiterRow);
38}