toc

package
v0.7.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 30, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package toc generates and renders tables of contents. It builds a hierarchical structure from headings and renders HTML navigation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CountEntries

func CountEntries(entries []TOCEntry) int

CountEntries returns the total number of TOC entries, including descendants.

Types

type Generator

type Generator struct {
}

Generator builds hierarchical TOC trees from flat heading lists.

func NewGenerator

func NewGenerator() *Generator

NewGenerator creates a new TOC generator.

func (*Generator) Generate

func (g *Generator) Generate(headings []HeadingInfo) []TOCEntry

Generate builds a hierarchical TOC tree from document-order headings.

func (*Generator) RenderHTML

func (g *Generator) RenderHTML(entries []TOCEntry) string

RenderHTML renders the TOC tree as nested HTML navigation.

type HeadingInfo

type HeadingInfo struct {
	Level int    // Heading level from 1 to 6.
	Text  string // Heading text.
	ID    string // Unique heading identifier, typically used as an anchor.
}

HeadingInfo stores heading metadata parsed from Markdown.

type TOCEntry

type TOCEntry struct {
	Level    int        // Heading level from 1 to 6.
	Title    string     // Heading text.
	ID       string     // Unique identifier used for anchor links.
	PageNum  int        // Optional page number for print-oriented output.
	Children []TOCEntry // Child entries.
}

TOCEntry represents one node in the TOC tree.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL