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: support quoted headings in document outline (#10454)
Péter Gyarmatib8a64f84c9f5
diff --git a/frontend/src/components/editor/chrome/panels/outline/__tests__/useActiveOutline.test.ts b/frontend/src/components/editor/chrome/panels/outline/__tests__/useActiveOutline.test.tsnew file mode 100644index 0000000000..062898f045--- /dev/null+++ b/frontend/src/components/editor/chrome/panels/outline/__tests__/useActiveOutline.test.ts@@ -0,0 +1,26 @@+/* Copyright 2026 Marimo. All rights reserved. */+import { describe, expect, it } from "vitest";+import { parseOutline } from "@/core/dom/outline";+import { findOutlineElements } from "../useActiveOutline";++describe("findOutlineElements", () => {+ it.each([+ "Design from the portfolio",+ 'Decorative Art of "Spanish California"',+ `The painter's "Study"`,+ ])("finds an id-less heading named %s", (name) => {+ const html = `<h3>${name}</h3>`;+ document.body.innerHTML = html;++ const outline = parseOutline({+ mimetype: "text/html",+ timestamp: 0,+ channel: "output",+ data: html,+ });++ expect(+ findOutlineElements(outline?.items ?? []).map(([element]) => element),+ ).toEqual([document.querySelector("h3")]);+ });+});diff --git a/frontend/src/core/dom/outline.ts b/frontend/src/core/dom/outline.tsindex 7821e18c36..2d360d05ea 100644--- a/frontend/src/core/dom/outline.ts+++ b/frontend/src/core/dom/outline.ts@@ -63,13 +63,36 @@ function getOutline(html: string): Outline | null {return { items };}+function toXPathStringLiteral(value: string): string {+ if (!value.includes('"')) {+ return `"${value}"`;+ }+ if (!value.includes("'")) {+ return `'${value}'`;+ }++ const segments = value.split('"');+ const literals: string[] = [];+ for (const [index, segment] of segments.entries()) {+ if (segment) {+ literals.push(`"${segment}"`);+ }+ if (index < segments.length - 1) {+ literals.push(`'"'`);+ }+ }+ return `concat(${literals.join(", ")})`;+}+export function headingToIdentifier(heading: Element): OutlineItem["by"] {const id = heading.id;if (id) {return { id };}- const name = heading.textContent;- return { path: `//${heading.tagName}[contains(., "${name}")]` };+ const name = heading.textContent ?? "";+ return {+ path: `//${heading.tagName}[contains(., ${toXPathStringLiteral(name)})]`,+ };}export function mergeOutlines(outlines: (Outline | null)[]): Outline {