tableofcontents

package
v0.120.3 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2023 License: Apache-2.0 Imports: 4 Imported by: 11

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = Config{
	StartLevel: 2,
	EndLevel:   3,
	Ordered:    false,
}

DefaultConfig is the default ToC configuration.

View Source
var Empty = &Fragments{
	Headings:    Headings{},
	HeadingsMap: map[string]*Heading{},
}

Empty is an empty ToC.

Functions

This section is empty.

Types

type Builder added in v0.111.0

type Builder struct {
	// contains filtered or unexported fields
}

Builder is used to build the ToC data structure.

func (*Builder) AddAt added in v0.111.0

func (b *Builder) AddAt(h *Heading, row, level int)

AddAt adds the heading to the ToC.

func (Builder) Build added in v0.111.0

func (b Builder) Build() *Fragments

Build returns the ToC.

type Config

type Config struct {
	// Heading start level to include in the table of contents, starting
	// at h1 (inclusive).
	// <docsmeta>{ "identifiers": ["h1"] }</docsmeta>
	StartLevel int

	// Heading end level, inclusive, to include in the table of contents.
	// Default is 3, a value of -1 will include everything.
	EndLevel int

	// Whether to produce a ordered list or not.
	Ordered bool
}

type Fragments added in v0.111.0

type Fragments struct {
	// Headings holds the top level headings.
	Headings Headings

	// Identifiers holds all the identifiers in the ToC as a sorted slice.
	// Note that collections.SortedStringSlice has both a Contains and Count method
	// that can be used to identify missing and duplicate IDs.
	Identifiers collections.SortedStringSlice

	// HeadingsMap holds all the headings in the ToC as a map.
	// Note that with duplicate IDs, the last one will win.
	HeadingsMap map[string]*Heading
}

Fragments holds the table of contents for a page.

func (*Fragments) ToHTML added in v0.111.0

func (toc *Fragments) ToHTML(startLevel, stopLevel int, ordered bool) template.HTML

ToHTML renders the ToC as HTML.

type Heading added in v0.84.1

type Heading struct {
	ID    string
	Title string

	Headings Headings
}

Heading holds the data about a heading and its children.

func (Heading) IsZero added in v0.84.1

func (h Heading) IsZero() bool

IsZero is true when no ID or Text is set.

type Headings added in v0.84.1

type Headings []*Heading

Headings holds the top level headings.

func (Headings) FilterBy added in v0.111.0

func (h Headings) FilterBy(fn func(*Heading) bool) Headings

FilterBy returns a new Headings slice with all headings that matches the given predicate. For internal use only.

Jump to

Keyboard shortcuts

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