ast

package
v0.0.197 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(w io.Writer, n Node, g Generator) error

Generate traverses the AST and calls the appropriate Generator method.

func Walk

func Walk(n Node, fn func(Node) error) error

Walk traverses the node tree depth-first without modifying nodes.

Types

type BaseNode

type BaseNode struct {
	Start   int
	End     int
	IsBlock bool
}

func (*BaseNode) GetPos

func (n *BaseNode) GetPos() (int, int)

func (*BaseNode) SetPos

func (n *BaseNode) SetPos(start, end int)

type Bold

type Bold struct {
	BaseNode
	Children []Node
}

Bold text.

func (*Bold) AddChild

func (b *Bold) AddChild(n Node)

func (*Bold) GetChildren

func (b *Bold) GetChildren() []Node

func (*Bold) String

func (b *Bold) String() string

func (*Bold) Transform

func (b *Bold) Transform(op func(Node) (Node, error)) (Node, error)

type Code

type Code struct {
	BaseNode
	InnerStart int
	InnerEnd   int
	Value      string
}

Code block.

func (*Code) String

func (c *Code) String() string

func (*Code) Transform

func (c *Code) Transform(op func(Node) (Node, error)) (Node, error)

type CodeIn

type CodeIn struct {
	BaseNode
	Language   string
	InnerStart int
	InnerEnd   int
	Value      string
}

CodeIn block with language specification.

func (*CodeIn) String

func (c *CodeIn) String() string

func (*CodeIn) Transform

func (c *CodeIn) Transform(op func(Node) (Node, error)) (Node, error)

type Container

type Container interface {
	Node
	AddChild(Node)
	GetChildren() []Node
}

Container represents a node that can hold other nodes.

type Custom

type Custom struct {
	BaseNode
	Tag      string
	Children []Node
}

Custom element for unrecognised tags.

func (*Custom) AddChild

func (c *Custom) AddChild(n Node)

func (*Custom) GetChildren

func (c *Custom) GetChildren() []Node

func (*Custom) String

func (c *Custom) String() string

func (*Custom) Transform

func (c *Custom) Transform(op func(Node) (Node, error)) (Node, error)

type Generator

type Generator interface {
	Root(w io.Writer, n *Root) error
	Text(w io.Writer, n *Text) error
	Bold(w io.Writer, n *Bold) error
	Italic(w io.Writer, n *Italic) error
	Underline(w io.Writer, n *Underline) error
	Sup(w io.Writer, n *Sup) error
	Sub(w io.Writer, n *Sub) error
	Link(w io.Writer, n *Link) error
	Image(w io.Writer, n *Image) error
	Code(w io.Writer, n *Code) error
	CodeIn(w io.Writer, n *CodeIn) error
	Quote(w io.Writer, n *Quote) error
	QuoteOf(w io.Writer, n *QuoteOf) error
	Spoiler(w io.Writer, n *Spoiler) error
	Indent(w io.Writer, n *Indent) error
	HR(w io.Writer, n *HR) error
	Custom(w io.Writer, n *Custom) error
}

Generator defines how to generate output for each node type. Implementations should write to w.

type HR

type HR struct {
	BaseNode
}

HR node.

func (*HR) String

func (h *HR) String() string

func (*HR) Transform

func (h *HR) Transform(op func(Node) (Node, error)) (Node, error)

type Image

type Image struct {
	BaseNode
	Src string
}

Image embeds an image.

func (*Image) String

func (i *Image) String() string

func (*Image) Transform

func (i *Image) Transform(op func(Node) (Node, error)) (Node, error)

type Indent

type Indent struct {
	BaseNode
	Children []Node
}

Indent node.

func (*Indent) AddChild

func (i *Indent) AddChild(n Node)

func (*Indent) GetChildren

func (i *Indent) GetChildren() []Node

func (*Indent) String

func (i *Indent) String() string

func (*Indent) Transform

func (i *Indent) Transform(op func(Node) (Node, error)) (Node, error)

type Italic

type Italic struct {
	BaseNode
	Children []Node
}

Italic text.

func (*Italic) AddChild

func (i *Italic) AddChild(n Node)

func (*Italic) GetChildren

func (i *Italic) GetChildren() []Node

func (*Italic) String

func (i *Italic) String() string

func (*Italic) Transform

func (i *Italic) Transform(op func(Node) (Node, error)) (Node, error)
type Link struct {
	BaseNode
	Href     string
	Children []Node
	IsBlock  bool
}

Link to a URL.

func (*Link) AddChild

func (l *Link) AddChild(n Node)

func (*Link) GetChildren

func (l *Link) GetChildren() []Node

func (*Link) IsImmediateClose

func (l *Link) IsImmediateClose() bool

func (*Link) String

func (l *Link) String() string

func (*Link) Transform

func (l *Link) Transform(op func(Node) (Node, error)) (Node, error)

type Node

type Node interface {
	fmt.Stringer

	Transform(op func(Node) (Node, error)) (Node, error)
	SetPos(start, end int)
	GetPos() (int, int)
	// contains filtered or unexported methods
}

Node represents a parsed element of markup.

type Quote

type Quote struct {
	BaseNode
	Children []Node
}

Quote node.

func (*Quote) AddChild

func (q *Quote) AddChild(n Node)

func (*Quote) GetChildren

func (q *Quote) GetChildren() []Node

func (*Quote) String

func (q *Quote) String() string

func (*Quote) Transform

func (q *Quote) Transform(op func(Node) (Node, error)) (Node, error)

type QuoteOf

type QuoteOf struct {
	BaseNode
	Name     string
	Children []Node
}

QuoteOf node.

func (*QuoteOf) AddChild

func (q *QuoteOf) AddChild(n Node)

func (*QuoteOf) GetChildren

func (q *QuoteOf) GetChildren() []Node

func (*QuoteOf) String

func (q *QuoteOf) String() string

func (*QuoteOf) Transform

func (q *QuoteOf) Transform(op func(Node) (Node, error)) (Node, error)

type Root

type Root struct {
	BaseNode
	Children []Node
}

Root is the top level node of a document.

func (*Root) AddChild

func (r *Root) AddChild(n Node)

func (*Root) GetChildren

func (r *Root) GetChildren() []Node

func (*Root) String

func (r *Root) String() string

func (*Root) Transform

func (r *Root) Transform(op func(Node) (Node, error)) (Node, error)

type Spoiler

type Spoiler struct {
	BaseNode
	Children []Node
}

Spoiler node.

func (*Spoiler) AddChild

func (s *Spoiler) AddChild(n Node)

func (*Spoiler) GetChildren

func (s *Spoiler) GetChildren() []Node

func (*Spoiler) String

func (s *Spoiler) String() string

func (*Spoiler) Transform

func (s *Spoiler) Transform(op func(Node) (Node, error)) (Node, error)

type Sub

type Sub struct {
	BaseNode
	Children []Node
}

Subscript text.

func (*Sub) AddChild

func (s *Sub) AddChild(n Node)

func (*Sub) GetChildren

func (s *Sub) GetChildren() []Node

func (*Sub) String

func (s *Sub) String() string

func (*Sub) Transform

func (s *Sub) Transform(op func(Node) (Node, error)) (Node, error)

type Sup

type Sup struct {
	BaseNode
	Children []Node
}

Superscript text.

func (*Sup) AddChild

func (s *Sup) AddChild(n Node)

func (*Sup) GetChildren

func (s *Sup) GetChildren() []Node

func (*Sup) String

func (s *Sup) String() string

func (*Sup) Transform

func (s *Sup) Transform(op func(Node) (Node, error)) (Node, error)

type Text

type Text struct {
	BaseNode
	Value string
}

Text contains plain text content.

func (*Text) String

func (t *Text) String() string

func (*Text) Transform

func (t *Text) Transform(op func(Node) (Node, error)) (Node, error)

type Underline

type Underline struct {
	BaseNode
	Children []Node
}

Underline text.

func (*Underline) AddChild

func (u *Underline) AddChild(n Node)

func (*Underline) GetChildren

func (u *Underline) GetChildren() []Node

func (*Underline) String

func (u *Underline) String() string

func (*Underline) Transform

func (u *Underline) Transform(op func(Node) (Node, error)) (Node, error)

Jump to

Keyboard shortcuts

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