parser

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseNode

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

BaseNode provides common functionality for all nodes

func NewBaseNode

func NewBaseNode(kind NodeType, rng Range) *BaseNode

NewBaseNode creates a new base node

func (*BaseNode) Accept

func (b *BaseNode) Accept(visitor Visitor) error

Accept implements the visitor pattern

func (*BaseNode) AddChild

func (b *BaseNode) AddChild(child Node)

AddChild adds a child node

func (*BaseNode) Children

func (b *BaseNode) Children() []Node

Children returns the child nodes

func (*BaseNode) Parent

func (b *BaseNode) Parent() Node

Parent returns the parent node

func (*BaseNode) Range

func (b *BaseNode) Range() Range

Range returns the source range

func (*BaseNode) RemoveChild

func (b *BaseNode) RemoveChild(child Node)

RemoveChild removes a child node

func (*BaseNode) SetParent

func (b *BaseNode) SetParent(parent Node)

SetParent sets the parent node

func (*BaseNode) Type

func (b *BaseNode) Type() NodeType

Type returns the node type

type Code

type Code struct {
	*BaseNode
	Content string
}

Code represents inline code (`code`)

func NewCode

func NewCode(content string, rng Range) *Code

NewCode creates a new code node

type CodeBlock

type CodeBlock struct {
	*BaseNode
	Language string
	Content  string
	Fenced   bool
}

CodeBlock represents a code block node

func NewCodeBlock

func NewCodeBlock(language, content string, fenced bool, rng Range) *CodeBlock

NewCodeBlock creates a new code block node

func (*CodeBlock) Accept

func (cb *CodeBlock) Accept(visitor Visitor) error

Accept implements the visitor pattern for CodeBlock

type Document

type Document struct {
	*BaseNode
	Title string
}

Document represents the root document node

func NewDocument

func NewDocument(rng Range) *Document

NewDocument creates a new document node

func (*Document) AddChild

func (d *Document) AddChild(child Node)

AddChild overrides BaseNode.AddChild to set the concrete Document as parent

func (*Document) FindListItemAtLine

func (d *Document) FindListItemAtLine(line int) *ListItem

FindListItemAtLine finds the list item that contains the given line number

type Emphasis

type Emphasis struct {
	*BaseNode
}

Emphasis represents emphasized text (*text* or _text_)

func NewEmphasis

func NewEmphasis(rng Range) *Emphasis

NewEmphasis creates a new emphasis node

type Heading

type Heading struct {
	*BaseNode
	Level int
	Text  string
}

Heading represents a heading node

func NewHeading

func NewHeading(level int, text string, rng Range) *Heading

NewHeading creates a new heading node

func (*Heading) Accept

func (h *Heading) Accept(visitor Visitor) error

Accept implements the visitor pattern for Heading

type Link struct {
	*BaseNode
	URL   string
	Title string
}

Link represents a link node

func NewLink(url, title string, rng Range) *Link

NewLink creates a new link node

type List

type List struct {
	*BaseNode
	Ordered bool
	Tight   bool
}

List represents a list node

func NewList

func NewList(ordered, tight bool, rng Range) *List

NewList creates a new list node

func (*List) Accept

func (l *List) Accept(visitor Visitor) error

Accept implements the visitor pattern for List

func (*List) AddChild

func (l *List) AddChild(child Node)

AddChild overrides BaseNode.AddChild to set the concrete List as parent

func (*List) GetListItems

func (l *List) GetListItems() []*ListItem

GetListItems returns all ListItem children of this List

type ListItem

type ListItem struct {
	*BaseNode
	TaskList  bool
	TaskState string // The actual task state value (e.g., " ", "x", "wip", "in-progress")
}

ListItem represents a list item node

func NewListItem

func NewListItem(taskList bool, taskState string, rng Range) *ListItem

NewListItem creates a new list item node

func (*ListItem) Accept

func (li *ListItem) Accept(visitor Visitor) error

Accept implements the visitor pattern for ListItem

func (*ListItem) FindParentList

func (li *ListItem) FindParentList() *List

FindParentList finds the parent List node for a given ListItem

func (*ListItem) GetListItemIndex

func (li *ListItem) GetListItemIndex() int

GetListItemIndex returns the index of this ListItem within its parent List

func (*ListItem) GetSiblingListItems

func (li *ListItem) GetSiblingListItems() []*ListItem

GetSiblingListItems returns all sibling ListItems in the same parent List

type Node

type Node interface {
	Type() NodeType
	Range() Range
	Parent() Node
	SetParent(Node)
	Children() []Node
	AddChild(Node)
	RemoveChild(Node)
	Accept(Visitor) error
}

Node represents a node in the document tree

type NodeType

type NodeType int

NodeType represents the type of a node in the document tree

const (
	// Block nodes
	NodeDocument NodeType = iota
	NodeHeading
	NodeParagraph
	NodeCodeBlock
	NodeBlockQuote
	NodeList
	NodeListItem
	NodeThematicBreak

	// Inline nodes
	NodeText
	NodeEmphasis
	NodeStrong
	NodeCode
	NodeLink
	NodeWikilink
	NodeAutoLink
	NodeRawHTML

	// Container nodes
	NodeContainer
)

func (NodeType) String

func (nt NodeType) String() string

String returns the string representation of a NodeType

type NotedownParser

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

NotedownParser implements the Parser interface using goldmark

func (*NotedownParser) Parse

func (p *NotedownParser) Parse(source []byte) (*Document, error)

Parse parses markdown source bytes into a document tree

func (*NotedownParser) ParseString

func (p *NotedownParser) ParseString(source string) (*Document, error)

ParseString parses markdown source string into a document tree

type Paragraph

type Paragraph struct {
	*BaseNode
}

Paragraph represents a paragraph node

func NewParagraph

func NewParagraph(rng Range) *Paragraph

NewParagraph creates a new paragraph node

type Parser

type Parser interface {
	Parse(source []byte) (*Document, error)
	ParseString(source string) (*Document, error)
}

Parser defines the interface for parsing markdown documents

func NewParser

func NewParser() Parser

NewParser creates a new Notedown parser with workspace configuration

type Position

type Position struct {
	Line   int // 1-based line number
	Column int // 1-based column number
	Offset int // 0-based byte offset
}

Position represents a position in the source document

type Range

type Range struct {
	Start Position
	End   Position
}

Range represents a range in the source document

type Strong

type Strong struct {
	*BaseNode
}

Strong represents strong text (**text** or __text__)

func NewStrong

func NewStrong(rng Range) *Strong

NewStrong creates a new strong node

type Text

type Text struct {
	*BaseNode
	Content string
}

Text represents a text node

func NewText

func NewText(content string, rng Range) *Text

NewText creates a new text node

type Visitor

type Visitor interface {
	Visit(node Node) error
}

Visitor defines the visitor pattern interface for traversing the document tree

type WalkFunc

type WalkFunc func(node Node) error

WalkFunc is a convenience type for creating visitors from functions

func (WalkFunc) Visit

func (f WalkFunc) Visit(node Node) error

Visit implements the Visitor interface

type Walker

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

Walker provides utilities for traversing document trees

func NewWalker

func NewWalker(visitor Visitor) *Walker

NewWalker creates a new tree walker

func (*Walker) Walk

func (w *Walker) Walk(node Node) error

Walk traverses the tree starting from the given node

type Wikilink struct {
	*BaseNode
	Target      string
	DisplayText string
}

Wikilink represents a wikilink node ([[page]] or [[page|display]])

func NewWikilink(target, displayText string, rng Range) *Wikilink

NewWikilink creates a new wikilink node

func (*Wikilink) Accept

func (w *Wikilink) Accept(visitor Visitor) error

Accept implements the visitor pattern for Wikilink

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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