headingdoc

package
v0.0.0-...-3a64406 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyName           = errors.New("heading has no name")
	ErrNotDocument         = errors.New("markdown ast node is not a document node")
	ErrUnsupportedL1Header = errors.New("only a single L1 header is allowed")
)

Functions

This section is empty.

Types

type Doc

type Doc struct {
	// Name is the name of the header of this section
	Name string
	// Level is the level of the header
	Level int
	// Content is a list of the markdown nodes that came after this header, and before any other header
	Content []ast.Node
	// Children is a list of headers that came after this header and are a lower level than this header
	Children []*Doc
	// Parent is the higher-level header that appeared in the document before this one.
	Parent *Doc
}

Doc is a convenience type that sorts a markdown document by headers.

func New

func New(root ast.Node) (*Doc, error)

New takes a root (ast.Document) markdown node and builds a Doc with it.

func NewFromReader

func NewFromReader(r io.Reader) (*Doc, error)

func (*Doc) Find

func (hd *Doc) Find(name string) []*Doc

Find searches this header and its subheaders for one matching the given name and level. Name is compared loosely, by checking in a case insensitive way whether the header contains the specified name.

func (*Doc) FindOne

func (hd *Doc) FindOne(name string) *Doc

FindOne returns the first result that Find would return.

Jump to

Keyboard shortcuts

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