Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

feat(table): visible markers for leading/trailing whitespace in string cells (#9256)

Kiran Gadhavebfa4845fa8ce
diff --git a/frontend/src/components/data-table/__tests__/columns.test.tsx b/frontend/src/components/data-table/__tests__/columns.test.tsx
index 185a2af6af..9779a9907d 100644
--- a/frontend/src/components/data-table/__tests__/columns.test.tsx
+++ b/frontend/src/components/data-table/__tests__/columns.test.tsx
@@ -749,6 +749,110 @@ describe("LocaleNumber", () => {
});
});
+describe("renderCellValue with string + edge whitespace", () => {
+ const createMockStringColumn = () =>
+ ({
+ id: "desc",
+ columnDef: {
+ meta: {
+ dataType: "string" as const,
+ dtype: "object",
+ },
+ },
+ getColumnFormatting: () => undefined,
+ getColumnWrapping: () => undefined,
+ applyColumnFormatting: (value: unknown) => value,
+ }) as unknown as Column<unknown>;
+
+ const renderWithProviders = (node: React.ReactNode) =>
+ render(
+ <I18nProvider locale="en-US">
+ <TooltipProvider>{node}</TooltipProvider>
+ </I18nProvider>,
+ );
+
+ it("renders edge whitespace markers and still detects the URL in the middle", () => {
+ const mockColumn = createMockStringColumn();
+ const value = " https://example.com ";
+ const result = renderCellValue({
+ column: mockColumn,
+ renderValue: () => value,
+ getValue: () => value,
+ selectCell: undefined,
+ cellStyles: "",
+ });
+
+ const { container } = renderWithProviders(result);
+
+ // URL detection runs on the middle, so the anchor is still rendered.
+ const link = container.querySelector("a");
+ expect(link).toBeTruthy();
+ expect(link?.href).toBe("https://example.com/");
+
+ // The link text is exactly the URL — no leading/trailing whitespace
+ // leaked into the anchor.
+ expect(link?.textContent).toBe("https://example.com");
+
+ // Both edge-whitespace marker containers are present and render
+ // visible glyphs (U+2423 "open box" for regular spaces).
+ const markerSpans = container.querySelectorAll(
+ "span[aria-label$='space'], span[aria-label$='spaces']",
+ );
+ expect(markerSpans.length).toBeGreaterThanOrEqual(2);
+ expect(container.textContent?.includes("\u2423")).toBe(true);
+ });
+
+ it("does not split URLs on whitespace padding (regression)", () => {
+ const mockColumn = createMockStringColumn();
+ // Trailing whitespace would previously be consumed by the URL regex
+ // (\S+). We render the middle only through parseContent to avoid that.
+ const value = "go here: https://example.com/path ";
+ const result = renderCellValue({
+ column: mockColumn,
+ renderValue: () => value,
+ getValue: () => value,
+ selectCell: undefined,
+ cellStyles: "",
+ });
+
+ const { container } = renderWithProviders(result);
+
+ const link = container.querySelector("a");
+ expect(link).toBeTruthy();
+ // href is URL-normalized by the browser — should not include the
+ // trailing spaces as part of the URL path.
+ expect(link?.href).toBe("https://example.com/path");
+ expect(link?.textContent?.trimEnd()).toBe("https://example.com/path");
+ });
+
+ it("renders no marker span when the string has no edge whitespace", () => {
+ const mockColumn = createMockStringColumn();
+ const value = "https://example.com";
+ const result = renderCellValue({
+ column: mockColumn,
+ renderValue: () => value,
+ getValue: () => value,
+ selectCell: undefined,
+ cellStyles: "",
+ });
+
+ const { container } = renderWithProviders(result);
+ // No marker glyph leaked through.
+ expect(container.textContent?.includes("\u2423")).toBe(false);
+ // And no WhitespaceMarkers wrapper was rendered at all. The component
+ // returns null for empty strings, and always sets an aria-label
+ // generated by `describeWhitespace` when it does render (e.g.
+ // "1 space", "2 spaces", "1 tab", "1 unicode whitespace").
+ // Matching the "space"/"spaces" suffix is enough here because the
+ // test value contains no whitespace, so no marker of any kind should
+ // appear.
+ const markerSpans = container.querySelectorAll(
+ "span[aria-label$='space'], span[aria-label$='spaces']",
+ );
+ expect(markerSpans.length).toBe(0);
+ });
+});
+
describe("renderCellValue with boolean values", () => {
const createMockColumn = () =>
({
diff --git a/frontend/src/components/data-table/__tests__/sentinel-cell.test.tsx b/frontend/src/components/data-table/__tests__/sentinel-cell.test.tsx
index ea13ebc2f6..b5a9490aa2 100644
--- a/frontend/src/components/data-table/__tests__/sentinel-cell.test.tsx
+++ b/frontend/src/components/data-table/__tests__/sentinel-cell.test.tsx
@@ -2,7 +2,7 @@
import { render } from "@testing-library/react";
import { describe, expect, it } from "vitest";
-import { SentinelCell } from "../sentinel-cell";
+import { SentinelCell, WhitespaceMarkers } from "../sentinel-cell";
import type { CellValueSentinel } from "../types";
function renderSentinel(sentinel: CellValueSentinel) {
@@ -10,6 +10,10 @@ function renderSentinel(sentinel: CellValueSentinel) {
return container.querySelector("span")!;
}
+function renderMarkers(value: string) {
+ return render(<WhitespaceMarkers value={value} />);
+}
+
describe("SentinelCell", () => {
it("renders null as None", () => {
const span = renderSentinel({ type: "null", value: null });
@@ -81,3 +85,87 @@ describe("SentinelCell", () => {
expect(span.getAttribute("title")).toBe("NaT (Not a Time)");
});
});
+
+describe("WhitespaceMarkers", () => {
+ it("renders nothing for empty string", () => {
+ const { container } = renderMarkers("");
+ expect(container.firstChild).toBeNull();
+ });
+
+ it("renders a single space as open box", () => {
+ const { container } = renderMarkers(" ");
+ const outer = container.querySelector("span")!;
+ expect(outer.textContent).toBe("\u2423");
+ expect(outer.getAttribute("aria-label")).toBe("1 space");
+ });
+
+ it("renders multiple spaces as multiple open boxes", () => {
+ const { container } = renderMarkers(" ");
+ const outer = container.querySelector("span")!;
+ expect(outer.textContent).toBe("\u2423\u2423\u2423");
+ expect(outer.getAttribute("aria-label")).toBe("3 spaces");
+ });
+
+ it("renders tab, newline, CR with escape labels", () => {
+ const { container } = renderMarkers("\t\n\r");
+ const outer = container.querySelector("span")!;
+ expect(outer.textContent).toBe("\\t\\n\\r");
+ });
+
+ it("renders each char in its own span for CSS spacing", () => {
+ const { container } = renderMarkers(" ");
+ const outer = container.querySelector("span")!;
+ // Outer wrapper + three inner spans (one per char)
+ expect(outer.querySelectorAll("span")).toHaveLength(3);
+ });
+
+ it("renders unknown whitespace (NBSP) as \\uXXXX escape", () => {
+ const { container } = renderMarkers("\u00a0");
+ const outer = container.querySelector("span")!;
+ expect(outer.textContent).toBe("\\u00a0");
+ });
+
+ it("renders BOM as \\ufeff", () => {
+ const { container } = renderMarkers("\ufeff");
+ const outer = container.querySelector("span")!;
+ expect(outer.textContent).toBe("\\ufeff");
+ });
+
+ it("renders en space and em space as escapes", () => {
+ const { container } = renderMarkers("\u2002\u2003");
+ const outer = container.querySelector("span")!;
+ expect(outer.textContent).toBe("\\u2002\\u2003");
+ });
+
+ it("mixes known glyphs and unknown escapes correctly", () => {
+ const { container } = renderMarkers(" \t\u00a0");
+ const outer = container.querySelector("span")!;
+ expect(outer.textContent).toBe("\u2423\\t\\u00a0");
+ });
+
+ it("describes mixed whitespace in aria-label", () => {
+ const { container } = renderMarkers(" \t\n");
+ const outer = container.querySelector("span")!;
+ expect(outer.getAttribute("aria-label")).toBe("1 space, 1 tab, 1 newline");
+ });
+
+ it("describes unknown whitespace as 'unicode whitespace'", () => {
+ const { container } = renderMarkers("\u00a0");
+ const outer = container.querySelector("span")!;
+ expect(outer.getAttribute("aria-label")).toBe("1 unicode whitespace");
+ });
+
+ it("pluralizes unknown whitespace in aria-label", () => {
+ const { container } = renderMarkers("\u00a0\u00a0\u2002");
+ const outer = container.querySelector("span")!;
+ expect(outer.getAttribute("aria-label")).toBe("3 unicode whitespaces");
+ });
+
+ it("mixes known and unknown whitespace labels", () => {
+ const { container } = renderMarkers(" \u00a0\t");
+ const outer = container.querySelector("span")!;
+ expect(outer.getAttribute("aria-label")).toBe(
+ "1 space, 1 unicode whitespace, 1 tab",
+ );
+ });
+});
diff --git a/frontend/src/components/data-table/__tests__/utils.test.ts b/frontend/src/components/data-table/__tests__/utils.test.ts
index 9315e59acc..0fafcdf232 100644
--- a/frontend/src/components/data-table/__tests__/utils.test.ts
+++ b/frontend/src/components/data-table/__tests__/utils.test.ts
@@ -7,6 +7,7 @@ import {
getClipboardContent,
getPageIndexForRow,
getRawValue,
+ splitLeadingTrailingWhitespace,
stringifyUnknownValue,
} from "../utils";
@@ -342,3 +343,101 @@ describe("getRawValue", () => {
expect(getRawValue(table, 5, "a")).toBeUndefined();
});
});
+
+describe("splitLeadingTrailingWhitespace", () => {
+ it("returns all empty for empty string", () => {
+ expect(splitLeadingTrailingWhitespace("")).toEqual({
+ leading: "",
+ middle: "",
+ trailing: "",
+ });
+ });
+
+ it("returns value as middle when no edge whitespace", () => {
+ expect(splitLeadingTrailingWhitespace("abc")).toEqual({
+ leading: "",
+ middle: "abc",
+ trailing: "",
+ });
+ });
+
+ it("preserves inner whitespace in middle", () => {
+ expect(splitLeadingTrailingWhitespace("abc d ef")).toEqual({
+ leading: "",
+ middle: "abc d ef",
+ trailing: "",
+ });
+ });
+
+ it("splits leading whitespace only", () => {
+ expect(splitLeadingTrailingWhitespace(" abc")).toEqual({
+ leading: " ",
+ middle: "abc",
+ trailing: "",
+ });
+ });
+
+ it("splits trailing whitespace only", () => {
+ expect(splitLeadingTrailingWhitespace("abc ")).toEqual({
+ leading: "",
+ middle: "abc",
+ trailing: " ",
+ });
+ });
+
+ it("splits both leading and trailing whitespace", () => {
+ expect(splitLeadingTrailingWhitespace(" abc ")).toEqual({
+ leading: " ",
+ middle: "abc",
+ trailing: " ",
+ });
+ });
+
+ it("handles mixed whitespace types at edges", () => {
+ expect(splitLeadingTrailingWhitespace("\t\n abc \r\t")).toEqual({
+ leading: "\t\n ",
+ middle: "abc",
+ trailing: " \r\t",
+ });
+ });
+
+ it("preserves inner whitespace when edges have whitespace", () => {
+ expect(splitLeadingTrailingWhitespace(" a b c ")).toEqual({
+ leading: " ",
+ middle: "a b c",
+ trailing: " ",
+ });
+ });
+
+ it("handles Unicode whitespace (NBSP) at edges", () => {
+ expect(splitLeadingTrailingWhitespace("\u00a0abc\u00a0")).toEqual({
+ leading: "\u00a0",
+ middle: "abc",
+ trailing: "\u00a0",
+ });
+ });
+
+ it("puts whitespace-only string in leading (caller should handle sentinel first)", () => {
+ expect(splitLeadingTrailingWhitespace(" ")).toEqual({
+ leading: " ",
+ middle: "",
+ trailing: "",
+ });
+ });
+
+ it("handles single whitespace char", () => {
+ expect(splitLeadingTrailingWhitespace(" ")).toEqual({
+ leading: " ",
+ middle: "",
+ trailing: "",
+ });
+ });
+
+ it("handles single non-whitespace char", () => {
+ expect(splitLeadingTrailingWhitespace("a")).toEqual({
+ leading: "",
+ middle: "a",
+ trailing: "",
+ });
+ });
+});
diff --git a/frontend/src/components/data-table/columns.tsx b/frontend/src/components/data-table/columns.tsx
index 5f7a51c57f..30679f0ef3 100644
--- a/frontend/src/components/data-table/columns.tsx
+++ b/frontend/src/components/data-table/columns.tsx
@@ -39,8 +39,8 @@ import {
INDEX_COLUMN_NAME,
isNumericType,
} from "./types";
-import { SentinelCell } from "./sentinel-cell";
-import { detectSentinel } from "./utils";
+import { SentinelCell, WhitespaceMarkers } from "./sentinel-cell";
+import { detectSentinel, splitLeadingTrailingWhitespace } from "./utils";
import { uniformSample } from "./uniformSample";
import { MarkdownUrlDetector, UrlDetector } from "./url-detector";
@@ -346,6 +346,7 @@ const PopoutColumn = ({
cellStyles,
selectCell,
rawStringValue,
+ edges,
contentClassName,
buttonText,
wrapped,
@@ -354,11 +355,25 @@ const PopoutColumn = ({
cellStyles?: string;
selectCell?: () => void;
rawStringValue: string;
+ // Edge whitespace shown as visible markers in the trigger; copy/title
+ // still use `rawStringValue`. Middle is sliced from `rawStringValue`.
+ edges?: { leading: string; trailing: string };
contentClassName?: string;
buttonText?: string;
wrapped?: boolean;
children: React.ReactNode;
}) => {
+ const hasEdgeWhitespace =
+ edges !== undefined &&
+ (edges.leading.length > 0 || edges.trailing.length > 0);
+
+ const displayText = hasEdgeWhitespace
+ ? rawStringValue.slice(
+ edges.leading.length,
+ rawStringValue.length - edges.trailing.length,
+ )
+ : rawStringValue;
+
return (
<EmotionCacheProvider container={null}>
<Popover>
@@ -377,7 +392,9 @@ const PopoutColumn = ({
)}
title={rawStringValue}
>
- {rawStringValue}
+ {edges ? <WhitespaceMarkers value={edges.leading} /> : null}
+ {displayText}
+ {edges ? <WhitespaceMarkers value={edges.trailing} /> : null}
</span>
</PopoverTrigger>
<PopoverContent
@@ -582,7 +599,13 @@ export function renderCellValue<TData, TValue>({
? String(column.applyColumnFormatting(value))
: String(renderValue());
- const parts = parseContent(stringValue);
+ const { leading, middle, trailing } =
+ splitLeadingTrailingWhitespace(stringValue);
+ const hasEdgeWhitespace = leading.length > 0 || trailing.length > 0;
+
+ // Parse only the inner content for URL detection so URLDetector doesn't
+ // split on the whitespace padding.
+ const parts = parseContent(hasEdgeWhitespace ? middle : stringValue);
const allMarkup = parts.every((part) => part.type !== "text");
if (allMarkup || stringValue.length < MAX_STRING_LENGTH || isWrapped) {
return (
@@ -590,7 +613,9 @@ export function renderCellValue<TData, TValue>({
onClick={selectCell}
className={cn(cellStyles, isWrapped && COLUMN_WRAPPING_STYLES)}
>
+ <WhitespaceMarkers value={leading} />
<UrlDetector parts={parts} />
+ <WhitespaceMarkers value={trailing} />
</div>
);
}
@@ -600,11 +625,15 @@ export function renderCellValue<TData, TValue>({
cellStyles={cellStyles}
selectCell={selectCell}
rawStringValue={stringValue}
+ edges={{ leading, trailing }}
contentClassName="max-h-64 overflow-auto whitespace-pre-wrap break-words text-sm w-96"
buttonText="X"
wrapped={isWrapped}
>
- <MarkdownUrlDetector content={stringValue} parts={parts} />
+ <MarkdownUrlDetector
+ content={stringValue}
+ parts={parseContent(stringValue)}
+ />
</PopoutColumn>
);
}
diff --git a/frontend/src/components/data-table/sentinel-cell.tsx b/frontend/src/components/data-table/sentinel-cell.tsx
index 56c694c72b..8863dafeb1 100644
--- a/frontend/src/components/data-table/sentinel-cell.tsx
+++ b/frontend/src/components/data-table/sentinel-cell.tsx
@@ -3,20 +3,30 @@
import type { CellValueSentinel, CellValueSentinelType } from "./types";
const WHITESPACE_CHARS: Record<string, { marker: string; name: string }> = {
- " ": { marker: "\u2423", name: "space" }, // open box (space symbol)
+ " ": { marker: "\u2423", name: "space" },
"\t": { marker: "\\t", name: "tab" },
"\n": { marker: "\\n", name: "newline" },
- "\r": { marker: "\\r", name: "newline" },
+ "\r": { marker: "\\r", name: "carriage return" },
};
-function renderWhitespaceMarkers(str: string): string {
- return [...str].map((ch) => WHITESPACE_CHARS[ch]?.marker ?? ch).join("");
+function renderWhitespaceMarkers(str: string): React.ReactNode[] {
+ return [...str].map((ch, i) => {
+ const entry = WHITESPACE_CHARS[ch];
+ const marker = entry
+ ? entry.marker
+ : `\\u${(ch.codePointAt(0) ?? 0).toString(16).padStart(4, "0")}`;
+ return (
+ <span key={i} className="mr-0.5 last:mr-0">
+ {marker}
+ </span>
+ );
+ });
}
function describeWhitespace(str: string): string {
const counts: Record<string, number> = {};
for (const ch of str) {
- const name = WHITESPACE_CHARS[ch]?.name ?? "character";
+ const name = WHITESPACE_CHARS[ch]?.name ?? "unicode whitespace";
counts[name] = (counts[name] ?? 0) + 1;
}
return Object.entries(counts)
@@ -25,7 +35,7 @@ function describeWhitespace(str: string): string {
}
interface SentinelConfig {
- label: (value: CellValueSentinel["value"]) => string;
+ label: (value: CellValueSentinel["value"]) => string | React.ReactNode[];
tooltip: (value: CellValueSentinel["value"]) => string;
ariaLabel: (value: CellValueSentinel["value"]) => string;
}
@@ -68,6 +78,24 @@ const SENTINEL_CONFIG: Record<CellValueSentinelType, SentinelConfig> = {
},
};
+export function WhitespaceMarkers({ value }: { value: string }) {
+ if (!value) {
+ return null;
+ }
+
+ const description = describeWhitespace(value);
+
+ return (
+ <span
+ className="text-muted-foreground opacity-60"
+ aria-label={description}
+ title={description}
+ >
+ {renderWhitespaceMarkers(value)}
+ </span>
+ );
+}
+
export function SentinelCell({
sentinel,
}: {
diff --git a/frontend/src/components/data-table/utils.ts b/frontend/src/components/data-table/utils.ts
index 6c70b35c84..96b92f9aaa 100644
--- a/frontend/src/components/data-table/utils.ts
+++ b/frontend/src/components/data-table/utils.ts
@@ -14,6 +14,51 @@ import {
} from "./types";
const WHITESPACE_ONLY_RE = /^[\s]+$/;
+const WHITESPACE_CHAR_RE = /\s/;
+const EDGE_WHITESPACE_RE = /^(\s*)([\s\S]*?)(\s*)$/;
+
+/**
+ * checks for leading and trailing whitespaces.
+ * Will run for every cell, so fast exits for common cases
+ *
+ * @param value - to split
+ * @returns - leading, middle, and trailing string where leading and trailing are whitespace string
+ */
+export function splitLeadingTrailingWhitespace(value: string): {
+ leading: string;
+ middle: string;
+ trailing: string;
+} {
+ const parts = {
+ leading: "",
+ middle: "",
+ trailing: "",
+ };
+ if (value.length === 0) {
+ return parts;
+ }
+
+ const firstWhitespaceCh = WHITESPACE_CHAR_RE.test(value[0]);
+ const lastWhitespaceCh = WHITESPACE_CHAR_RE.test(value[value.length - 1]);
+
+ // if does not start or end with ws
+ if (!firstWhitespaceCh && !lastWhitespaceCh) {
+ parts.middle = value;
+ return parts;
+ }
+
+ const match = EDGE_WHITESPACE_RE.exec(value);
+ if (!match) {
+ parts.middle = value;
+ return parts;
+ }
+
+ parts.leading = match[1] ?? "";
+ parts.middle = match[2] ?? "";
+ parts.trailing = match[3] ?? "";
+
+ return parts;
+}
/**
* Convenience function to load table data.
diff --git a/marimo/_smoke_tests/tables/sentinel_values.py b/marimo/_smoke_tests/tables/whitespace_sentinel_rendering.py
similarity index 62%
rename from marimo/_smoke_tests/tables/sentinel_values.py
rename to marimo/_smoke_tests/tables/whitespace_sentinel_rendering.py
index d9cbe389a7..9f83532481 100644
--- a/marimo/_smoke_tests/tables/sentinel_values.py
+++ b/marimo/_smoke_tests/tables/whitespace_sentinel_rendering.py
@@ -1,3 +1,12 @@
+# /// script
+# requires-python = ">=3.11"
+# dependencies = [
+# "marimo",
+# "pandas",
+# "polars",
+# ]
+# ///
+
import marimo
__generated_with = "0.23.1"
@@ -7,19 +16,22 @@ app = marimo.App(width="medium")
@app.cell(hide_code=True)
def _(mo):
mo.md("""
- # Sentinel Values in Tables
+ # Whitespace & Sentinel Rendering in Tables
Tables should visually distinguish sentinel values (null, empty string,
- whitespace-only strings, NaN, ±Infinity, NaT) from normal data.
+ whitespace-only strings, NaN, ±Infinity, NaT) and strings with
+ leading/trailing whitespace from normal data.
Each framework has its own semantics — this notebook exercises the
rendering across Polars, Pandas (object dtype), and Pandas nullable
- dtypes.
+ dtypes, plus a framework-agnostic section for edge-whitespace markers.
## Expected rendering
- `None` / null → muted italic pill labeled `None`
- Empty string `"\"` → blank in cell, `<empty>` pill in filter dropdown
- - Whitespace (` `, `\t`, `\n`) → visible markers in a pill
+ - Whitespace-only (` `, ` `, `
+ `) → visible markers in a pill
+ - Strings with content + leading/trailing whitespace → inline markers on the edges (inner whitespace unchanged)
- `NaN` / `inf` / `-inf` → muted pills
- `NaT` (pandas) → muted pill labeled `NaT` in datetime columns
- Literal string `"null"`, `"NaN"`, etc. → rendered as normal text
@@ -295,5 +307,123 @@ def _(mo, pd):
return
[email protected](hide_code=True)
+def _(mo):
+ mo.md("""
+ ## Strings with edge whitespace
+
+ Distinct from the whitespace-only sentinel above: strings with **content
+ plus leading or trailing whitespace** render with inline markers on the
+ edges, while inner whitespace is untouched.
+
+ Rendering is frontend-only — backend-agnostic — so these cases use
+ plain Python dicts.
+ """)
+ return
+
+
[email protected](hide_code=True)
+def _(mo):
+ baseline_rows = [
+ {"label": "plain", "s": "abc d"},
+ {"label": "underscores only (shape ref)", "s": "___abc_d___"},
+ {"label": "1 space + underscores", "s": " ___abc_d___ "},
+ ]
+ mo.vstack(
+ [
+ mo.md("### Comparison baseline"),
+ mo.ui.table(selection=None, data=baseline_rows),
+ ]
+ )
+ return
+
+
[email protected](hide_code=True)
+def _(mo):
+ supported_rows = [
+ {"label": "leading spaces", "s": " abc d"},
+ {"label": "trailing spaces", "s": "abc d "},
+ {"label": "both spaces", "s": " abc d "},
+ {"label": "leading tab", "s": "\tabc d"},
+ {"label": "trailing tab", "s": "abc d\t"},
+ {"label": "leading newline", "s": "\nabc d"},
+ {"label": "trailing newline", "s": "abc d\n"},
+ {"label": "carriage return", "s": "\rabc d\r"},
+ {"label": "mixed", "s": " \t\nabc d\n\t "},
+ ]
+ mo.vstack(
+ [
+ mo.md("### Supported marker chars (space, tab, \\n, \\r)"),
+ mo.ui.table(selection=None, data=supported_rows),
+ ]
+ )
+ return
+
+
[email protected](hide_code=True)
+def _(mo):
+ unicode_rows = [
+ {"label": "nbsp (U+00A0)", "s": "\xa0abc d\xa0"},
+ {"label": "en space (U+2002)", "s": "\u2002abc d\u2002"},
+ {"label": "em space (U+2003)", "s": "\u2003abc d\u2003"},
+ {"label": "thin space (U+2009)", "s": "\u2009abc d\u2009"},
+ {"label": "ideographic (U+3000)", "s": "\u3000abc d\u3000"},
+ {"label": "zero-width (U+200B)", "s": "\u200babc d\u200b"},
+ {"label": "BOM (U+FEFF)", "s": "\ufeffabc d\ufeff"},
+ {"label": "line sep (U+2028)", "s": "\u2028abc d\u2028"},
+ {"label": "para sep (U+2029)", "s": "\u2029abc d\u2029"},
+ {"label": "form feed (\\f)", "s": "\fabc d\f"},
+ {"label": "vertical tab (\\v)", "s": "\vabc d\v"},
+ # Adjacent-escape cases: verify spacing between multi-char \uXXXX markers
+ {"label": "3x nbsp adjacent", "s": "\xa0\xa0\xa0abc d\xa0\xa0\xa0"},
+ {
+ "label": "mixed adjacent (nbsp + en + em)",
+ "s": "\xa0\u2002\u2003abc d\u2003\u2002\xa0",
+ },
+ {"label": "nbsp + regular space", "s": "\xa0 \xa0abc d\xa0 \xa0"},
+ ]
+ mo.vstack(
+ [
+ mo.md("### Unicode whitespace — detected by \\s, not in marker table"),
+ mo.md(
+ "These are detected as whitespace (so they get split from `middle`) but render as the raw char since `WHITESPACE_CHARS` has no mapping — documenting the current gap."
+ ),
+ mo.ui.table(selection=None, data=unicode_rows),
+ ]
+ )
+ return
+
+
[email protected](hide_code=True)
+def _(mo):
+ # Strings >= 50 chars collapse into a PopoutColumn (click the row to
+ # expand). Expected: the *trigger* shows edge whitespace markers plus
+ # the middle text; the *expanded popover* preserves all whitespace via
+ # `whitespace-pre-wrap` and the copy icon yields the raw string.
+ popout_rows = [
+ {
+ "label": "long string + edge whitespace (popout)",
+ "s": " "
+ + ("The quick brown fox jumps over the lazy dog. " * 2)
+ + " ",
+ },
+ {
+ "label": "long string URL + edge whitespace",
+ "s": (
+ " "
+ + "https://www.example.com/search?q=the+quick+brown+fox+jumps+over+the+lazy+dog&lang=en&page=1"
+ + " "
+ ),
+ },
+ ]
+ mo.vstack(
+ [
+ mo.md("### Popout column (long strings, ≥ 50 chars)"),
+ mo.ui.table(selection=None, data=popout_rows),
+ ]
+ )
+ return
+
+
if __name__ == "__main__":
app.run()