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.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
fix: render multiline tooltips with normalized line endings (#10850)
Myles Scolnick18e2e49db505
diff --git a/frontend/src/plugins/core/RenderHTML.tsx b/frontend/src/plugins/core/RenderHTML.tsxindex ecb726b053..0c782ad003 100644--- a/frontend/src/plugins/core/RenderHTML.tsx+++ b/frontend/src/plugins/core/RenderHTML.tsx@@ -262,18 +262,30 @@ const wrapTooltipTargets: TransformFn = (if (tagName.startsWith("marimo-")) {return undefined;}- const tooltipContent = domNode.attribs["data-tooltip"];- // Convert literal newlines to <br/> elements so the tooltip renders- // multiline content. is decoded to \n by html-react-parser- // before this transform runs.- const lines = tooltipContent.split("\n");- const content: ReactNode =- lines.length === 1- ? tooltipContent- : lines.flatMap((line, i) =>- i === 0 ? [line] : [<br key={i} />, line],- );- return <Tooltip content={content}>{reactNode as JSX.Element}</Tooltip>;+ const tooltipContent = domNode.attribs["data-tooltip"].replace(+ /^[\r\n]+|[\r\n]+$/g,+ "",+ );+ return (+ <Tooltip+ content={+ tooltipContent.includes("\n") ? (+ <span className="whitespace-pre-wrap">+ {tooltipContent.split(/\r?\n/).map((line, i) => (+ <React.Fragment key={i}>+ {i > 0 && <br />}+ {line}+ </React.Fragment>+ ))}+ </span>+ ) : (+ tooltipContent+ )+ }+ >+ {reactNode as JSX.Element}+ </Tooltip>+ );}};diff --git a/frontend/src/plugins/core/__test__/RenderHTML.test.ts b/frontend/src/plugins/core/__test__/RenderHTML.test.tsindex f7c57cd67c..bf14737489 100644--- a/frontend/src/plugins/core/__test__/RenderHTML.test.ts+++ b/frontend/src/plugins/core/__test__/RenderHTML.test.ts@@ -1,5 +1,7 @@/* Copyright 2026 Marimo. All rights reserved. */import type { ExtractAtomValue } from "jotai";+import { isValidElement, type ReactNode } from "react";+import { renderToStaticMarkup } from "react-dom/server";import { afterEach, beforeEach, describe, expect, test } from "vitest";import { hasRunAnyCellAtom } from "@/components/editor/cell/useRunCells";import { userConfigAtom } from "@/core/config/config";@@ -458,13 +460,21 @@ describe("wrapTooltipTargets", () => {expect(result).toMatchInlineSnapshot(`<Tooltipcontent={- [- "Line A",- <br />,- "Line B",- <br />,- "Line C",- ]+ <span+ className="whitespace-pre-wrap"+ >+ <React.Fragment>+ Line A+ </React.Fragment>+ <React.Fragment>+ <br />+ Line B+ </React.Fragment>+ <React.Fragment>+ <br />+ Line C+ </React.Fragment>+ </span>}><span@@ -483,11 +493,17 @@ describe("wrapTooltipTargets", () => {expect(parseHtml({ html })).toMatchInlineSnapshot(`<Tooltipcontent={- [- "Line A",- <br />,- "Line B",- ]+ <span+ className="whitespace-pre-wrap"+ >+ <React.Fragment>+ Line A+ </React.Fragment>+ <React.Fragment>+ <br />+ Line B+ </React.Fragment>+ </span>}><span@@ -514,6 +530,113 @@ describe("wrapTooltipTargets", () => {</Tooltip>`);});++ test.each([+ ["CRLF", "A\r\nB", '<span class="whitespace-pre-wrap">A<br/>B</span>'],+ [+ "encoded CRLF",+ "A B",+ '<span class="whitespace-pre-wrap">A<br/>B</span>',+ ],+ ["leading newline", "\nA", "A"],+ ["trailing newline", "A\n", "A"],+ [+ "boundary newlines",+ "\n\nA\nB\n\n",+ '<span class="whitespace-pre-wrap">A<br/>B</span>',+ ],+ [+ "boundary CRLF",+ " A B ",+ '<span class="whitespace-pre-wrap">A<br/>B</span>',+ ],+ ["only newlines", "\n\n", ""],+ ["only CRLF", " ", ""],+ [+ "internal blank line",+ "A\n\nB",+ '<span class="whitespace-pre-wrap">A<br/><br/>B</span>',+ ],+ [+ "spaces and tabs",+ "\n A\t\n\tB \n",+ '<span class="whitespace-pre-wrap"> A\t<br/>\tB </span>',+ ],+ [+ "HTML text",+ "<b>A</b>\nB",+ '<span class="whitespace-pre-wrap"><b>A</b><br/>B</span>',+ ],+ ])("data-tooltip handles %s", (_, content, expected) => {+ const result = parseHtml({+ html: `<span data-tooltip="${content}">Hover me</span>`,+ });+ if (!isValidElement<{ content: ReactNode }>(result)) {+ throw new Error("Expected a Tooltip element");+ }+ expect(renderToStaticMarkup(result.props.content)).toBe(expected);+ });++ test("data-tooltip with newline renders as line breaks", () => {+ const html = '<span data-tooltip="Line one\nLine two">Hover me</span>';+ expect(parseHtml({ html })).toMatchInlineSnapshot(`+ <Tooltip+ content={+ <span+ className="whitespace-pre-wrap"+ >+ <React.Fragment>+ Line one+ </React.Fragment>+ <React.Fragment>+ <br />+ Line two+ </React.Fragment>+ </span>+ }+ >+ <span+ data-tooltip="Line one+ Line two"+ >+ Hover me+ </span>+ </Tooltip>+ `);+ });++ test("data-tooltip with multiple newlines renders all as line breaks", () => {+ const html = '<span data-tooltip="A\nB\nC">Hover me</span>';+ expect(parseHtml({ html })).toMatchInlineSnapshot(`+ <Tooltip+ content={+ <span+ className="whitespace-pre-wrap"+ >+ <React.Fragment>+ A+ </React.Fragment>+ <React.Fragment>+ <br />+ B+ </React.Fragment>+ <React.Fragment>+ <br />+ C+ </React.Fragment>+ </span>+ }+ >+ <span+ data-tooltip="A+ B+ C"+ >+ Hover me+ </span>+ </Tooltip>+ `);+ });});describe("parseHtml with < nad >", () => {