-
Notifications
You must be signed in to change notification settings - Fork 751
feat 5834: add outline - mo.outline() #6430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
14bc619
feat 5834: add outline - mo.outline()
maxkoretskyi de44b9f
feat 5834: add outline - mo.outline()
maxkoretskyi a042ed7
feat 5834: add outline - mo.outline()
maxkoretskyi bf43246
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /* Copyright 2024 Marimo. All rights reserved. */ | ||
| import type { JSX } from "react"; | ||
| import { z } from "zod"; | ||
| import { notebookOutline } from "@/core/cells/cells"; | ||
| import { store } from "@/core/state/jotai"; | ||
| import { OutlineList } from "../../components/editor/chrome/panels/outline/floating-outline"; | ||
| import { | ||
| findOutlineElements, | ||
| useActiveOutline, | ||
| } from "../../components/editor/chrome/panels/outline/useActiveOutline"; | ||
| import type { IStatelessPlugin, IStatelessPluginProps } from "../stateless-plugin"; | ||
|
|
||
| interface Data { | ||
| label?: string; | ||
| } | ||
|
|
||
| export class OutlinePlugin implements IStatelessPlugin<Data> { | ||
| tagName = "marimo-outline"; | ||
|
|
||
| validator = z.object({ | ||
| label: z.string().optional(), | ||
| }); | ||
|
|
||
| render(props: IStatelessPluginProps<Data>): JSX.Element { | ||
| const { label } = props.data; | ||
| const { items } = store.get(notebookOutline); | ||
| const headerElements = findOutlineElements(items); | ||
|
|
||
| const { activeHeaderId, activeOccurrences } = useActiveOutline(headerElements); | ||
|
Check failure on line 29 in frontend/src/plugins/layout/OutlinePlugin.tsx
|
||
|
|
||
| if (items.length === 0) { | ||
| return ( | ||
| <div className="text-muted-foreground text-sm p-4 border border-dashed border-border rounded-lg"> | ||
| No outline found. Add markdown headings to your notebook to create an outline. | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <div className="border border-border rounded-lg"> | ||
| {label && ( | ||
| <div className="px-4 py-2 border-b border-border font-medium text-sm"> | ||
| {label} | ||
| </div> | ||
| )} | ||
| <OutlineList | ||
| className="max-h-[400px]" | ||
| items={items} | ||
| activeHeaderId={activeHeaderId} | ||
| activeOccurrences={activeOccurrences} | ||
| /> | ||
| </div> | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # Copyright 2024 Marimo. All rights reserved. | ||
| from __future__ import annotations | ||
|
|
||
| from marimo._output.hypertext import Html | ||
| from marimo._output.rich_help import mddoc | ||
| from marimo._plugins.core.web_component import build_stateless_plugin | ||
|
|
||
|
|
||
| @mddoc | ||
| def outline(*, label: str = "") -> Html: | ||
| """Display a table of contents outline showing all markdown headers in the notebook. | ||
|
|
||
| The outline automatically extracts all markdown headers from executed cells | ||
| and displays them in a hierarchical structure with clickable navigation. | ||
|
|
||
| Examples: | ||
| Basic outline: | ||
| ```python | ||
| mo.outline() | ||
| ``` | ||
|
|
||
| With custom label: | ||
| ```python | ||
| mo.outline(label="Table of Contents") | ||
| ``` | ||
|
|
||
| Args: | ||
| label (str, optional): A descriptive label for the outline. Defaults to "". | ||
|
|
||
| Returns: | ||
| Html: An HTML object that renders the outline component. | ||
| """ | ||
| return Html( | ||
| build_stateless_plugin( | ||
| component_name="marimo-outline", | ||
| args={"label": label}, | ||
| ) | ||
| ) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this won't re-render on changes. you will need to create a new react component and then call
useAtomValue(notebookOutline)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you will want to wrap the component in a
<Provider store={store}too