indexer

package
v0.0.0-...-66ecaaf Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GitHubFlavoredMarkdown

func GitHubFlavoredMarkdown(heading string) string

GitHubFlavoredMarkdown is an AnchorFunc that transforms heading text into GitHub Flavored Markdown anchors. Heading text is converted to a GFM anchor by first converting all text to lowercase, removing all non-word, non-hyphen, and non-space characters, and then replacing all spaces with hyphens.

Ref: https://github.com/gjtorikian/html-pipeline/blob/main/lib/html/pipeline/toc_filter.rb

Types

type AnchorFunc

type AnchorFunc func(heading string) (anchor string)

An AnchorFunc is a function that converts raw header text into an anchor that is appropriate for use in a URL.

type DocumentIndex

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

A DocumentIndex maps from anchors to Sections.

func Index

func Index(document *ast.Document, source []byte, options ...IndexOption) *DocumentIndex

Index walks a Document, converts the raw text of each heading to an anchor, and returns a DocumentIndex that maps from anchors to lists of sections. Headings are converted to GitHub Flavored Markdown anchors by default. Each section begins with either

func (*DocumentIndex) Lookup

func (index *DocumentIndex) Lookup(anchor string) ([]*Section, bool)

Lookup returns the list of sections with the given anchor. Sections appear in the list in the same order in which they appear in the source document.

func (*DocumentIndex) TableOfContents

func (index *DocumentIndex) TableOfContents() *Section

TableOfContents returns the root fo the document's section tree.

type IndexOption

type IndexOption func(i *indexer)

An IndexOption affects the behavior of the Index function.

func WithAnchors

func WithAnchors(anchors AnchorFunc) IndexOption

WithAnchors configures the AnchorFunc used by the indexer to convert

type Section

type Section struct {
	ID     int
	Level  int
	Anchor string

	Start ast.Node
	End   ast.Node

	Subsections []*Section
}

A Section represents a collection of nodes under a Heading (or the start of the document).

func (*Section) Walk

func (s *Section) Walk(walker ast.Walker) error

Walk calls ast.Walk on each node in the section.

Jump to

Keyboard shortcuts

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