gmast

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

gmast provides some helper functions for working with goldmark's AST. Useful for writing NodeUnmarshalers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendChild added in v0.0.3

func AppendChild[T ast.Node](parent T, children ...ast.Node) (theParent T)

AppendChild is a chainable version of ast.Node.AppendChild. Builds a new AST in a single call.

func AppendHeadingChild added in v0.0.3

func AppendHeadingChild[T ast.Node](heading T, children ...ast.Node) (theParent T)

AppendHeadingChild appends a child to the last sibling of the heading before a new higher-level heading. Conceptually, this is the same as AppendChild.

func FindSibling added in v0.0.3

func FindSibling(node ast.Node, isMatch func(node ast.Node) bool) ast.Node

FindSibling finds the first direct sibling of a node that matches the given predicate. If no match is found, returns nil.

func ForEachChild

func ForEachChild(node ast.Node, source []byte, fn func(child ast.Node, index int))

ForEachChild runs a callback on each direct child of a node.

func ForEachListItem

func ForEachListItem(node *ast.List, source []byte, fn func(item ast.Node, index int))

ForEachListItem runs a callback on each list item in a list.

func IsHeadingLevelBelow added in v0.0.3

func IsHeadingLevelBelow(node ast.Node, level int) bool

IsHeadingLevelBelow checks if a node is a heading that is outside a given level's children.

func LastChildOfHeading added in v0.0.3

func LastChildOfHeading(node ast.Node) (sibling ast.Node, err error)

LastChildOfHeading returns the last node that is before a heading of a lower level or the end of the document.

func NewHashtag added in v0.0.3

func NewHashtag(tag string, source []byte) (node ast.Node, newSource []byte)

NewHashtag returns a new hashtag.Node with the text set up correctly.

func NewParagraph added in v0.0.3

func NewParagraph(newText string, source []byte) (node ast.Node, newSource []byte)

NewParagraph is a helper to build a new paragraph with a single text segment.

func NewSegment added in v0.0.3

func NewSegment(newText string, source []byte) (text.Segment, []byte)

NewSegment builds a new text.Segment and appends its content to the source in a single call.

func NewSpace added in v0.0.3

func NewSpace(source []byte) (node ast.Node, newSource []byte)

NewSpace returns a new space text segment for adding space between inline nodes.

func NewTextSegment added in v0.0.3

func NewTextSegment(newText string, source []byte) (textSegment *ast.Text, newSource []byte)

NewTextSegment builds a new ast.TextSegment and appends its content to the source in a single call.

func WalkSiblingsUntil added in v0.0.1

func WalkSiblingsUntil(node ast.Node, walker ast.Walker) error

Do a depth-first walk of the AST, calling the walker function on each node, going to siblings, until the walker returns WalkStop or an error or hits EOF.

Types

This section is empty.

Jump to

Keyboard shortcuts

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