-
-
Notifications
You must be signed in to change notification settings - Fork 67
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
How to get the content of TOC #138
Comments
I don't quite understand the logic of this extension, so I can't help you implement it, it's up to you. Thank you. |
@condorheroblog This editor is built on top of Tiptap. You can create a custom hook to pull the ToC from the editor and then build a separate component to display it. I built something similar for myself -- ### useTableOfContents.ts (hook) export interface TableOfContentsItem { export function useTableOfContents(editor: Editor | null) { const getItems = useCallback(() => {
}, [editor]) useEffect(() => {
}, [editor, getItems]) return items ToC (Component -- This is a floating component I created for testing but you should be able to edit it into whatever you want)`import React, { useState } from 'react' interface TableOfContentsProps { export function TableOfContents({ className, editor }: TableOfContentsProps) { const handleItemClick = (id: string) => { const renderHeadingItem = (item: TableOfContentsItem, index: number) => {
} return ( Contents<Button variant="ghost" size="sm" onClick={() => setExpanded(false)} aria-label="Collapse table of contents" > <ScrollArea className="p-4" style={{ maxHeight: 'calc(100vh - 100px)' }}> {items.map((item, index) => renderHeadingItem(item, index))} ) : ( <Button variant="outline" size="sm" onClick={() => setExpanded(true)} aria-label="Expand table of contents" className="fixed bottom-4 right-4 shadow-md rounded-full p-3 bg-background z-50" > )} </> ) } ` ![]() |
Good job👍 For the convenience of users, invite you to submit a PR😁 |
I need the outline content to be on the left or right side of the editor, rather than inside the editor. Are there corresponding events exposed that I can use directly?
The text was updated successfully, but these errors were encountered: