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
Add interactive doc lookup for `data-marimo-doc` in cell output (#8343)
Trevor Manz9c426b76a247
diff --git a/frontend/src/core/documentation/DocHoverTarget.tsx b/frontend/src/core/documentation/DocHoverTarget.tsxnew file mode 100644index 0000000000..fd35cb4547--- /dev/null+++ b/frontend/src/core/documentation/DocHoverTarget.tsx@@ -0,0 +1,23 @@+/* Copyright 2026 Marimo. All rights reserved. */++import type { ReactNode } from "react";+import { useDebouncedCallback } from "@/hooks/useDebounce";+import { requestOutputDocumentation } from "./doc-lookup";++export const DocHoverTarget: React.FC<{+ qualifiedName: string;+ children: ReactNode;+}> = ({ qualifiedName, children }) => {+ const handleMouseEnter = useDebouncedCallback(() => {+ requestOutputDocumentation(qualifiedName);+ }, 100);++ return (+ <span+ onMouseEnter={handleMouseEnter}+ onMouseLeave={() => handleMouseEnter.cancel()}+ >+ {children}+ </span>+ );+};diff --git a/frontend/src/core/documentation/doc-lookup.ts b/frontend/src/core/documentation/doc-lookup.tsnew file mode 100644index 0000000000..d163f3e8cc--- /dev/null+++ b/frontend/src/core/documentation/doc-lookup.ts@@ -0,0 +1,50 @@+/* Copyright 2026 Marimo. All rights reserved. */++import { getCells } from "@/core/cells/cells";+import { AUTOCOMPLETER } from "@/core/codemirror/completion/Autocompleter";+import { store } from "@/core/state/jotai";+import { Logger } from "@/utils/Logger";+import { documentationAtom } from "./state";++/**+ * Request documentation for a qualified Python name (e.g. "torch.nn.Linear")+ * by piggybacking on the existing code-completion system.+ *+ * We send the qualified name as the "document" to the autocomplete endpoint.+ * Jedi resolves it and returns the docstring in the completion info.+ */+export async function requestOutputDocumentation(+ qualifiedName: string,+): Promise<void> {+ // We need any valid cell_id for the completion request.+ const cellId = getCells().inOrderIds.at(0);+ if (!cellId) {+ return;+ }++ try {+ const message = await AUTOCOMPLETER.request({+ document: qualifiedName,+ cellId,+ });++ if (!message || message.options.length === 0) {+ return;+ }++ // Find the option matching the last segment of the qualified name+ const shortName = qualifiedName.split(".").pop() ?? qualifiedName;++ const defaultOption = message.options[0];+ const match =+ message.options.find((o) => o.name === shortName) ?? defaultOption;++ if (match?.completion_info) {+ store.set(documentationAtom, {+ documentation: match.completion_info,+ });+ }+ } catch (error) {+ Logger.debug(`Doc lookup failed for "${qualifiedName}"`, error);+ }+}diff --git a/frontend/src/plugins/core/RenderHTML.tsx b/frontend/src/plugins/core/RenderHTML.tsxindex b88c249fb0..1c13f08c90 100644--- a/frontend/src/plugins/core/RenderHTML.tsx+++ b/frontend/src/plugins/core/RenderHTML.tsx@@ -14,6 +14,7 @@ import React, {} from "react";import { CopyClipboardIcon } from "@/components/icons/copy-icon";import { QueryParamPreservingLink } from "@/components/ui/query-param-preserving-link";+import { DocHoverTarget } from "@/core/documentation/DocHoverTarget";import { sanitizeHtml, useSanitizeHtml } from "./sanitize";type ReplacementFn = NonNullable<HTMLReactParserOptions["replace"]>;@@ -146,6 +147,19 @@ const addCopyButtonToCodehilite: TransformFn = (}};+// Wrap elements with data-marimo-doc attribute in a DocHoverTarget+const wrapDocHoverTargets: TransformFn = (+ reactNode: ReactNode,+ domNode: DOMNode,+): JSX.Element | undefined => {+ if (domNode instanceof Element && domNode.attribs?.["data-marimo-doc"]) {+ const qualifiedName = domNode.attribs["data-marimo-doc"];+ return (+ <DocHoverTarget qualifiedName={qualifiedName}>{reactNode}</DocHoverTarget>+ );+ }+};+const CopyableCode = ({ children }: { children: ReactNode }) => {const ref = useRef<HTMLDivElement>(null);return (@@ -224,6 +238,7 @@ function parseHtml({const transformFunctions: TransformFn[] = [addCopyButtonToCodehilite,preserveQueryParamsInAnchorLinks,+ wrapDocHoverTargets,removeWrappingBodyTags,removeWrappingHtmlTags,];