Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GitHubFlavoredMarkdown ¶
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 ¶
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