# TableOfContentsNode
Class Inherits Node
## About
`TableOfContentsNode` lists the document's headings as links, indented by level, and keeps the list current as headings are added, edited, or removed. Pressing an entry scrolls to its heading.
```xojo
Editor.NodeTypes.Add(New GraffitiProEditor.TableOfContentsNode)
Editor.AddNode(New GraffitiProEditor.TableOfContentsNode(2))
```
`MaximumLevel`, 3 by default, is the deepest heading level listed: 2 lists Heading 1 and Heading 2. Headings inside containers, such as columns and collapsible sections, are listed in document order. Headings with no text are left out.
## Methods
| Name | Parameters | Return Type | Description |
| --- | :---: | :---: | --- |
| CanImportHTML | element As GraffitiProEditor.HTMLSupport.HTMLElement | Boolean | Returns whether the supplied element is a table of contents this node type exported. |
| Constructor | maximumLevel As Integer = 3 | (None) | Creates a table of contents listing headings down to the supplied level, Heading 3 by default. |
| Duplicate | (None) | Node | Returns an independent copy of this table of contents. |
| FromHTML | element As GraffitiProEditor.HTMLSupport.HTMLElement | Boolean | Imports a table of contents this node type exported to HTML. Its entries come from the document, not the HTML. |
| FromJSON | data As JSONItem | Boolean | Restores the maximum heading level from JSON. |
| HandlePress | x As Double <br> y As Double | Boolean | Scrolls the editor to the heading of the entry at the specified document coordinates, and returns whether an entry was pressed. |
| HTMLTags | (None) | String | Returns the HTML tag names supported by this node type. |
| InspectorSections | (None) | InspectorSection | Returns the inspector sections for the deepest heading level listed. |
| LocalizeToolbarItem | strings As GraffitiProEditor.Editor | (None) | Sets this node type's toolbar item text from the supplied editor's localization properties. |
| PerformToolbarAction | editor As Editor <br> selectedItem As DesktopMenuItem | (None) | Adds a new table of contents to the editor. |
| PlainText | (None) | String | Returns an empty string: the entries repeat the document's headings. |
| PreferredHeight | g As Graphics <br> availableWidth As Double | Double | Returns the height of the entries, one line each. |
| Render | g As Graphics <br> bounds As Rect <br> selected As Boolean | (None) | Draws one entry per heading, indented by level. |
| ToHTML | (None) | String | Returns the entries as a navigation element of links to the headings' anchors. |
| ToJSON | (None) | JSONItem | Returns the maximum heading level as maximumLevel. The entries are not stored; they come from the document's headings. |
| ToMarkdown | (None) | String | Returns the entries as a nested Markdown list of links to the headings' anchors. |
| TranslateLayout | offsetX As Double <br> offsetY As Double | (None) | Offsets this node and the frames of its entries by the supplied distances. |
| TypeName | (None) | String | Returns the display name for this node type. |
## Properties
| Name | Type | Default Value | Description |
| --- | :---: | :---: | --- |
| MaximumLevel | Integer | (None) | Gets or sets the deepest heading level listed, from 1 to 6. The default is 3. |
## Notes
### JSON HTML and Markdown
The entries come from the document, so only `MaximumLevel` is saved: JSON stores it as `maximumLevel`, and HTML as the `data-maximum-level` attribute of a `nav` element marked with `data-graffiti-toc`.
HTML is a list of links to each heading's `HeadingNode.Anchor`, which heading export writes as the heading's `id`. Markdown is a nested list of the same links, which GitHub resolves to its heading anchors. `PlainText` is empty, so the entries are not counted by `Statistics` or found by `Search` a second time.
After each change the editor asks every table of contents to recollect its headings and redraws only those whose entries changed. Recollecting walks the document's nodes, not its text, so it stays cheap as the document grows.