ast

package
v2.1.6 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package ast defines AST nodes that represent markdown elements.

Index

Constants

This section is empty.

Variables

View Source
var KindAutoLink = NewNodeKind("AutoLink")

KindAutoLink is a NodeKind of the AutoLink node.

View Source
var KindBlockquote = NewNodeKind("Blockquote")

KindBlockquote is a NodeKind of the Blockquote node.

View Source
var KindCodeBlock = NewNodeKind("CodeBlock")

KindCodeBlock is a NodeKind of the CodeBlock node.

View Source
var KindCodeSpan = NewNodeKind("CodeSpan")

KindCodeSpan is a NodeKind of the CodeSpan node.

View Source
var KindDocument = NewNodeKind("Document")

KindDocument is a NodeKind of the Document node.

View Source
var KindEmphasis = NewNodeKind("Emphasis")

KindEmphasis is a NodeKind of the Emphasis node.

View Source
var KindHTMLBlock = NewNodeKind("HTMLBlock")

KindHTMLBlock is a NodeKind of the HTMLBlock node.

View Source
var KindHeading = NewNodeKind("Heading")

KindHeading is a NodeKind of the Heading node.

View Source
var KindImage = NewNodeKind("Image")

KindImage is a NodeKind of the Image node.

View Source
var KindLink = NewNodeKind("Link")

KindLink is a NodeKind of the Link node.

View Source
var KindLinkReferenceDefinition = NewNodeKind("LinkReferenceDefinition")

KindLinkReferenceDefinition is a NodeKind of the LinkReferenceDefinition node.

View Source
var KindList = NewNodeKind("List")

KindList is a NodeKind of the List node.

View Source
var KindListItem = NewNodeKind("ListItem")

KindListItem is a NodeKind of the ListItem node.

View Source
var KindParagraph = NewNodeKind("Paragraph")

KindParagraph is a NodeKind of the Paragraph node.

View Source
var KindRawHTML = NewNodeKind("RawHTML")

KindRawHTML is a NodeKind of the RawHTML node.

View Source
var KindStrong = NewNodeKind("Strong")

KindStrong is a NodeKind of the Strong node.

View Source
var KindText = NewNodeKind("Text")

KindText is a NodeKind of the Text node.

View Source
var KindThematicBreak = NewNodeKind("ThematicBreak")

KindThematicBreak is a NodeKind of the ThematicBreak node.

Functions

func IsParagraph

func IsParagraph(node Node) bool

IsParagraph returns true if the given node is a Paragraph node, otherwise false.

func Walk

func Walk(n Node, walker Walker) error

Walk walks a AST tree by the depth first search algorithm.

func WithLinkReference

func WithLinkReference(kind ReferenceLinkKind, value text.MultiLineValue) interface {
	LinkOption
	ImageOption
}

WithLinkReference returns a LinkOption that sets the reference of a link or image.

func WithLinkTitle

func WithLinkTitle(title text.MultiLineValue) interface {
	LinkOption
	ImageOption
	LinkReferenceDefinitionOption
}

WithLinkTitle returns a LinkOption that sets the title of a link or image.

Types

type Attribute

type Attribute struct {
	Name  string
	Value text.MultiLineValue
}

An Attribute is an attribute of the Node.

type AutoLink struct {
	BaseInline

	// Destination is the URL used for the href attribute.
	// For email autolinks, it includes the "mailto:" prefix.
	Destination text.SingleLineValue

	// Label is the display text shown inside the link element.
	Label text.SingleLineValue

	// Text is the original text as parsed from source, including any
	// surrounding syntax characters (e.g. "<" and ">" for CommonMark autolinks).
	Text text.SingleLineValue
}

An AutoLink struct represents an autolink of the Markdown text.

func NewAutoLink(destination, label text.SingleLineValue, opts ...AutoLinkOption) *AutoLink

NewAutoLink returns a new AutoLink node with the given destination, label, and options.

func (*AutoLink) Attribute added in v2.1.6

func (n *AutoLink) Attribute(name string) (text.MultiLineValue, bool)

Attribute implements Node.Attribute.

func (*AutoLink) Attributes added in v2.1.6

func (n *AutoLink) Attributes() []Attribute

Attributes implements Node.Attributes.

func (*AutoLink) Dump

func (n *AutoLink) Dump(_ []byte) *NodeDump

Dump implements Node.Dump.

func (*AutoLink) Kind

func (n *AutoLink) Kind() NodeKind

Kind implements Node.Kind.

func (*AutoLink) NextSibling added in v2.1.6

func (n *AutoLink) NextSibling() Node

NextSibling implements Node.NextSibling.

func (*AutoLink) Parent added in v2.1.6

func (n *AutoLink) Parent() Node

Parent implements Node.Parent.

func (*AutoLink) PreviousSibling added in v2.1.6

func (n *AutoLink) PreviousSibling() Node

PreviousSibling implements Node.PreviousSibling.

func (*AutoLink) RemoveAttributes added in v2.1.6

func (n *AutoLink) RemoveAttributes()

RemoveAttributes implements Node.RemoveAttributes.

func (*AutoLink) SetAttribute added in v2.1.6

func (n *AutoLink) SetAttribute(name string, value text.MultiLineValue)

SetAttribute implements Node.SetAttribute.

func (*AutoLink) SetNextSibling added in v2.1.6

func (n *AutoLink) SetNextSibling(v Node)

SetNextSibling implements Node.SetNextSibling.

func (*AutoLink) SetParent added in v2.1.6

func (n *AutoLink) SetParent(v Node)

SetParent implements Node.SetParent.

func (*AutoLink) SetPreviousSibling added in v2.1.6

func (n *AutoLink) SetPreviousSibling(v Node)

SetPreviousSibling implements Node.SetPreviousSibling.

type AutoLinkOption

type AutoLinkOption interface {
	// contains filtered or unexported methods
}

AutoLinkOption is an option for AutoLink nodes.

func WithAutoLinkText

func WithAutoLinkText(text text.SingleLineValue) AutoLinkOption

WithAutoLinkText returns an AutoLinkOption that sets the original source text of an autolink.

type BaseBlock

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

A BaseBlock struct implements the Node interface partially.

func (*BaseBlock) AppendSource

func (b *BaseBlock) AppendSource(seg text.Segment)

AppendSource implements BlockNode.AppendSource.

func (*BaseBlock) Attribute added in v2.1.6

func (n *BaseBlock) Attribute(name string) (text.MultiLineValue, bool)

Attribute implements Node.Attribute.

func (*BaseBlock) Attributes added in v2.1.6

func (n *BaseBlock) Attributes() []Attribute

Attributes implements Node.Attributes.

func (*BaseBlock) HasBlankPreviousLines

func (b *BaseBlock) HasBlankPreviousLines() bool

HasBlankPreviousLines implements Node.HasBlankPreviousLines.

func (*BaseBlock) NextSibling added in v2.1.6

func (n *BaseBlock) NextSibling() Node

NextSibling implements Node.NextSibling.

func (*BaseBlock) Parent added in v2.1.6

func (n *BaseBlock) Parent() Node

Parent implements Node.Parent.

func (*BaseBlock) PreviousSibling added in v2.1.6

func (n *BaseBlock) PreviousSibling() Node

PreviousSibling implements Node.PreviousSibling.

func (*BaseBlock) RemoveAttributes added in v2.1.6

func (n *BaseBlock) RemoveAttributes()

RemoveAttributes implements Node.RemoveAttributes.

func (*BaseBlock) SetAttribute added in v2.1.6

func (n *BaseBlock) SetAttribute(name string, value text.MultiLineValue)

SetAttribute implements Node.SetAttribute.

func (*BaseBlock) SetBlankPreviousLines

func (b *BaseBlock) SetBlankPreviousLines(v bool)

SetBlankPreviousLines implements Node.SetBlankPreviousLines.

func (*BaseBlock) SetNextSibling added in v2.1.6

func (n *BaseBlock) SetNextSibling(v Node)

SetNextSibling implements Node.SetNextSibling.

func (*BaseBlock) SetParent added in v2.1.6

func (n *BaseBlock) SetParent(v Node)

SetParent implements Node.SetParent.

func (*BaseBlock) SetPreviousSibling added in v2.1.6

func (n *BaseBlock) SetPreviousSibling(v Node)

SetPreviousSibling implements Node.SetPreviousSibling.

func (*BaseBlock) SetSource

func (b *BaseBlock) SetSource(v []text.Segment)

SetSource implements BlockNode.SetSource.

func (*BaseBlock) Source

func (b *BaseBlock) Source() []text.Segment

Source implements BlockNode.Source.

type BaseInline

type BaseInline struct {
	BaseNode
}

A BaseInline struct implements the Node interface partially.

func (*BaseInline) Attribute added in v2.1.6

func (n *BaseInline) Attribute(name string) (text.MultiLineValue, bool)

Attribute implements Node.Attribute.

func (*BaseInline) Attributes added in v2.1.6

func (n *BaseInline) Attributes() []Attribute

Attributes implements Node.Attributes.

func (*BaseInline) FirstRune added in v2.0.2

func (b *BaseInline) FirstRune(source []byte) (rune, bool)

FirstRune implements InlineNode.FirstRune.

func (*BaseInline) LastRune added in v2.0.2

func (b *BaseInline) LastRune(source []byte) (rune, bool)

LastRune implements InlineNode.LastRune.

func (*BaseInline) NextSibling added in v2.1.6

func (n *BaseInline) NextSibling() Node

NextSibling implements Node.NextSibling.

func (*BaseInline) Parent added in v2.1.6

func (n *BaseInline) Parent() Node

Parent implements Node.Parent.

func (*BaseInline) PreviousSibling added in v2.1.6

func (n *BaseInline) PreviousSibling() Node

PreviousSibling implements Node.PreviousSibling.

func (*BaseInline) RemoveAttributes added in v2.1.6

func (n *BaseInline) RemoveAttributes()

RemoveAttributes implements Node.RemoveAttributes.

func (*BaseInline) SetAttribute added in v2.1.6

func (n *BaseInline) SetAttribute(name string, value text.MultiLineValue)

SetAttribute implements Node.SetAttribute.

func (*BaseInline) SetNextSibling added in v2.1.6

func (n *BaseInline) SetNextSibling(v Node)

SetNextSibling implements Node.SetNextSibling.

func (*BaseInline) SetParent added in v2.1.6

func (n *BaseInline) SetParent(v Node)

SetParent implements Node.SetParent.

func (*BaseInline) SetPreviousSibling added in v2.1.6

func (n *BaseInline) SetPreviousSibling(v Node)

SetPreviousSibling implements Node.SetPreviousSibling.

type BaseNode

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

A BaseNode struct implements the Node interface partially.

func (*BaseNode) AppendChild

func (n *BaseNode) AppendChild(v Node)

AppendChild implements Node.AppendChild .

func (*BaseNode) Attribute

func (n *BaseNode) Attribute(name string) (text.MultiLineValue, bool)

Attribute implements Node.Attribute.

func (*BaseNode) Attributes

func (n *BaseNode) Attributes() []Attribute

Attributes implements Node.Attributes.

func (*BaseNode) ChildCount

func (n *BaseNode) ChildCount() int

ChildCount implements Node.ChildCount .

func (*BaseNode) Children

func (n *BaseNode) Children() iter.Seq[Node]

Children implements Node.Children .

func (*BaseNode) FirstChild

func (n *BaseNode) FirstChild() Node

FirstChild implements Node.FirstChild .

func (*BaseNode) HasChildren

func (n *BaseNode) HasChildren() bool

HasChildren implements Node.HasChildren .

func (*BaseNode) Init

func (n *BaseNode) Init(self Node)

Init initializes this node. Init must be called in each node's constructor.

func (*BaseNode) InsertAfter

func (n *BaseNode) InsertAfter(target, insertee Node)

InsertAfter implements Node.InsertAfter .

func (*BaseNode) InsertBefore

func (n *BaseNode) InsertBefore(target, insertee Node)

InsertBefore implements Node.InsertBefore .

func (*BaseNode) LastChild

func (n *BaseNode) LastChild() Node

LastChild implements Node.LastChild .

func (*BaseNode) NextSibling

func (n *BaseNode) NextSibling() Node

NextSibling implements Node.NextSibling.

func (*BaseNode) OwnerDocument

func (n *BaseNode) OwnerDocument() *Document

OwnerDocument implements Node.OwnerDocument.

func (*BaseNode) Parent

func (n *BaseNode) Parent() Node

Parent implements Node.Parent.

func (*BaseNode) Pos

func (n *BaseNode) Pos() int

Pos implements Node.Pos .

func (*BaseNode) PreviousSibling

func (n *BaseNode) PreviousSibling() Node

PreviousSibling implements Node.PreviousSibling.

func (*BaseNode) RemoveAttributes

func (n *BaseNode) RemoveAttributes()

RemoveAttributes implements Node.RemoveAttributes.

func (*BaseNode) RemoveChild

func (n *BaseNode) RemoveChild(v Node)

RemoveChild implements Node.RemoveChild .

func (*BaseNode) RemoveChildren

func (n *BaseNode) RemoveChildren()

RemoveChildren implements Node.RemoveChildren .

func (*BaseNode) ReplaceChild

func (n *BaseNode) ReplaceChild(target, insertee Node)

ReplaceChild implements Node.ReplaceChild .

func (*BaseNode) ReplaceChildInPlace added in v2.1.6

func (n *BaseNode) ReplaceChildInPlace(target, insertee Node)

ReplaceChildInPlace swaps target with insertee at target's slot in n's child list without touching target's own parent/prev/next fields.

func (*BaseNode) SetAttribute

func (n *BaseNode) SetAttribute(name string, value text.MultiLineValue)

SetAttribute implements Node.SetAttribute.

func (*BaseNode) SetNextSibling

func (n *BaseNode) SetNextSibling(v Node)

SetNextSibling implements Node.SetNextSibling.

func (*BaseNode) SetParent

func (n *BaseNode) SetParent(v Node)

SetParent implements Node.SetParent.

func (*BaseNode) SetPos

func (n *BaseNode) SetPos(v int)

SetPos implements Node.SetPos .

func (*BaseNode) SetPreviousSibling

func (n *BaseNode) SetPreviousSibling(v Node)

SetPreviousSibling implements Node.SetPreviousSibling.

type BlockNode

type BlockNode interface {
	Node

	// HasBlankPreviousLines returns true if the row before this node is blank,
	// otherwise false.
	HasBlankPreviousLines() bool

	// SetBlankPreviousLines sets whether the row before this node is blank.
	SetBlankPreviousLines(v bool)

	// Source returns text segments that hold positions in a source.
	// For nodes whose content is parsed into inline nodes, this holds the raw
	// source text used as the input for inline parsing. Nodes that do not parse
	// their content as inline elements return an empty slice.
	Source() []text.Segment

	// SetSource sets text segments that hold positions in a source.
	SetSource([]text.Segment)

	// AppendSource appends a text segment to the source.
	AppendSource(text.Segment)
	// contains filtered or unexported methods
}

A BlockNode interface is a Node that represents a block element. Some block nodes (e.g. Paragraph, Heading) hold source text segments that are later parsed into inline nodes; others (e.g. CodeBlock, HTMLBlock) do not use this mechanism and leave Source empty.

type Blockquote

type Blockquote struct {
	BaseBlock
}

A Blockquote struct represents an blockquote block of Markdown text.

func NewBlockquote

func NewBlockquote() *Blockquote

NewBlockquote returns a new Blockquote node.

func (*Blockquote) Attribute added in v2.1.6

func (n *Blockquote) Attribute(name string) (text.MultiLineValue, bool)

Attribute implements Node.Attribute.

func (*Blockquote) Attributes added in v2.1.6

func (n *Blockquote) Attributes() []Attribute

Attributes implements Node.Attributes.

func (*Blockquote) Dump

func (n *Blockquote) Dump(_ []byte) *NodeDump

Dump implements Node.Dump .

func (*Blockquote) Kind

func (n *Blockquote) Kind() NodeKind

Kind implements Node.Kind.

func (*Blockquote) NextSibling added in v2.1.6

func (n *Blockquote) NextSibling() Node

NextSibling implements Node.NextSibling.

func (*Blockquote) Parent added in v2.1.6

func (n *Blockquote) Parent() Node

Parent implements Node.Parent.

func (*Blockquote) PreviousSibling added in v2.1.6

func (n *Blockquote) PreviousSibling() Node

PreviousSibling implements Node.PreviousSibling.

func (*Blockquote) RemoveAttributes added in v2.1.6

func (n *Blockquote) RemoveAttributes()

RemoveAttributes implements Node.RemoveAttributes.

func (*Blockquote) SetAttribute added in v2.1.6

func (n *Blockquote) SetAttribute(name string, value text.MultiLineValue)

SetAttribute implements Node.SetAttribute.

func (*Blockquote) SetNextSibling added in v2.1.6

func (n *Blockquote) SetNextSibling(v Node)

SetNextSibling implements Node.SetNextSibling.

func (*Blockquote) SetParent added in v2.1.6

func (n *Blockquote) SetParent(v Node)

SetParent implements Node.SetParent.

func (*Blockquote) SetPreviousSibling added in v2.1.6

func (n *Blockquote) SetPreviousSibling(v Node)

SetPreviousSibling implements Node.SetPreviousSibling.

type CodeBlock

type CodeBlock struct {

	// CodeBlockKind indicates whether this is an indented or fenced code block.
	CodeBlockKind CodeBlockKind

	// Info is the info string of a fenced code block (e.g. language identifier).
	// It is empty for indented code blocks.
	Info text.SingleLineValue

	// Value holds the raw content of this code block for rendering.
	Value text.Lines
	// contains filtered or unexported fields
}

A CodeBlock struct represents a code block of Markdown text.

func NewCodeBlock

func NewCodeBlock(kind CodeBlockKind, value text.Lines, opts ...CodeBlockOption) *CodeBlock

NewCodeBlock returns a new CodeBlock node with the given kind and value.

func (*CodeBlock) AppendSource added in v2.1.6

func (b *CodeBlock) AppendSource(_ text.Segment)

func (*CodeBlock) Dump

func (n *CodeBlock) Dump(_ []byte) *NodeDump

Dump implements Node.Dump.

func (*CodeBlock) HasBlankPreviousLines added in v2.1.6

func (b *CodeBlock) HasBlankPreviousLines() bool

func (*CodeBlock) Kind

func (n *CodeBlock) Kind() NodeKind

Kind implements Node.Kind.

func (*CodeBlock) Language

func (n *CodeBlock) Language(source []byte) (string, bool)

Language returns the language extracted from the info string. Language returns false if there is no info string.

func (*CodeBlock) Pos added in v2.1.6

func (b *CodeBlock) Pos() int

func (*CodeBlock) SetBlankPreviousLines added in v2.1.6

func (b *CodeBlock) SetBlankPreviousLines(v bool)

func (*CodeBlock) SetPos added in v2.1.6

func (b *CodeBlock) SetPos(v int)

func (*CodeBlock) SetSource added in v2.1.6

func (b *CodeBlock) SetSource(_ []text.Segment)

func (*CodeBlock) Source added in v2.1.6

func (b *CodeBlock) Source() []text.Segment

type CodeBlockKind

type CodeBlockKind int

CodeBlockKind represents the kind of a CodeBlock: indented or fenced.

const (
	// CodeBlockKindIndented indicates an indented code block (4-space or tab indent).
	CodeBlockKindIndented CodeBlockKind = iota + 1
	// CodeBlockKindFenced indicates a fenced code block (“` or ~~~).
	CodeBlockKindFenced
)

func (CodeBlockKind) String

func (k CodeBlockKind) String() string

String returns a human-readable name of the CodeBlockKind.

type CodeBlockOption

type CodeBlockOption interface {
	// contains filtered or unexported methods
}

CodeBlockOption is an option for CodeBlock nodes.

func WithCodeBlockInfo

func WithCodeBlockInfo(info text.SingleLineValue) CodeBlockOption

WithCodeBlockInfo returns a CodeBlockOption that sets the info string of a fenced code block.

type CodeSpan

type CodeSpan struct {

	// Value holds the content of this code span.
	// The content is sourced from the raw Markdown text and may span multiple
	// source lines.
	//
	// This value is expected to be a single line; CommonMark requires that code span content is
	// normalized to a single line by replacing newlines with spaces.
	//
	// Code spans that span multiple lines and return multiple indices from [text.Value].Indices()
	// should return normalized single-line data from the Bytes, Str, and Value methods of [text.Value].
	Value text.Value
	// contains filtered or unexported fields
}

A CodeSpan struct represents a code span of Markdown text.

func NewCodeSpan

func NewCodeSpan(value text.Value) *CodeSpan

NewCodeSpan returns a new CodeSpan node with the given value.

Given value is expected to be a single line; CommonMark requires that code span content is normalized to a single line by replacing newlines with spaces.

You should use CodeBlock for code that you really want to treat as multiple lines.

Code spans that span multiple lines and return multiple indices from text.Value.Indices() should return normalized single-line data from the Bytes, Str, and Value methods of text.Value.

func (*CodeSpan) AppendChild added in v2.1.6

func (n *CodeSpan) AppendChild(_ Node)

AppendChild implements Node.AppendChild.

func (*CodeSpan) Attribute added in v2.1.6

func (n *CodeSpan) Attribute(name string) (text.MultiLineValue, bool)

Attribute implements Node.Attribute.

func (*CodeSpan) Attributes added in v2.1.6

func (n *CodeSpan) Attributes() []Attribute

Attributes implements Node.Attributes.

func (*CodeSpan) ChildCount added in v2.1.6

func (n *CodeSpan) ChildCount() int

ChildCount implements Node.ChildCount.

func (*CodeSpan) Children added in v2.1.6

func (n *CodeSpan) Children() iter.Seq[Node]

Children implements Node.Children.

func (*CodeSpan) Dump

func (n *CodeSpan) Dump(_ []byte) *NodeDump

Dump implements Node.Dump.

func (*CodeSpan) FirstChild added in v2.1.6

func (n *CodeSpan) FirstChild() Node

FirstChild implements Node.FirstChild.

func (*CodeSpan) FirstRune added in v2.0.2

func (n *CodeSpan) FirstRune(source []byte) (rune, bool)

FirstRune implements InlineNode.FirstRune.

func (*CodeSpan) HasChildren added in v2.1.6

func (n *CodeSpan) HasChildren() bool

HasChildren implements Node.HasChildren.

func (*CodeSpan) InsertAfter added in v2.1.6

func (n *CodeSpan) InsertAfter(_ Node, _ Node)

InsertAfter implements Node.InsertAfter.

func (*CodeSpan) InsertBefore added in v2.1.6

func (n *CodeSpan) InsertBefore(_ Node, _ Node)

InsertBefore implements Node.InsertBefore.

func (*CodeSpan) IsBlank

func (n *CodeSpan) IsBlank(source []byte) bool

IsBlank returns true if this node consists of spaces, otherwise false.

func (*CodeSpan) Kind

func (n *CodeSpan) Kind() NodeKind

Kind implements Node.Kind.

func (*CodeSpan) LastChild added in v2.1.6

func (n *CodeSpan) LastChild() Node

LastChild implements Node.LastChild.

func (*CodeSpan) LastRune added in v2.0.2

func (n *CodeSpan) LastRune(source []byte) (rune, bool)

LastRune implements InlineNode.LastRune.

func (*CodeSpan) NextSibling added in v2.1.6

func (n *CodeSpan) NextSibling() Node

NextSibling implements Node.NextSibling.

func (*CodeSpan) OwnerDocument added in v2.1.6

func (n *CodeSpan) OwnerDocument() *Document

OwnerDocument implements Node.OwnerDocument.

func (*CodeSpan) Parent added in v2.1.6

func (n *CodeSpan) Parent() Node

Parent implements Node.Parent.

func (*CodeSpan) Pos added in v2.1.6

func (n *CodeSpan) Pos() int

Pos implements Node.Pos.

func (*CodeSpan) PreviousSibling added in v2.1.6

func (n *CodeSpan) PreviousSibling() Node

PreviousSibling implements Node.PreviousSibling.

func (*CodeSpan) RemoveAttributes added in v2.1.6

func (n *CodeSpan) RemoveAttributes()

RemoveAttributes implements Node.RemoveAttributes.

func (*CodeSpan) RemoveChild added in v2.1.6

func (n *CodeSpan) RemoveChild(_ Node)

RemoveChild implements Node.RemoveChild.

func (*CodeSpan) RemoveChildren added in v2.1.6

func (n *CodeSpan) RemoveChildren()

RemoveChildren implements Node.RemoveChildren.

func (*CodeSpan) ReplaceChild added in v2.1.6

func (n *CodeSpan) ReplaceChild(_ Node, _ Node)

ReplaceChild implements Node.ReplaceChild.

func (*CodeSpan) SetAttribute added in v2.1.6

func (n *CodeSpan) SetAttribute(name string, value text.MultiLineValue)

SetAttribute implements Node.SetAttribute.

func (*CodeSpan) SetNextSibling added in v2.1.6

func (n *CodeSpan) SetNextSibling(v Node)

SetNextSibling implements Node.SetNextSibling.

func (*CodeSpan) SetParent added in v2.1.6

func (n *CodeSpan) SetParent(v Node)

SetParent implements Node.SetParent.

func (*CodeSpan) SetPos added in v2.1.6

func (n *CodeSpan) SetPos(_ int)

SetPos implements Node.SetPos.

func (*CodeSpan) SetPreviousSibling added in v2.1.6

func (n *CodeSpan) SetPreviousSibling(v Node)

SetPreviousSibling implements Node.SetPreviousSibling.

type Document

type Document struct {
	BaseBlock
	// contains filtered or unexported fields
}

A Document struct is a root node of Markdown text.

func NewDocument

func NewDocument() *Document

NewDocument returns a new Document node.

func (*Document) AddMeta

func (n *Document) AddMeta(key string, value any)

AddMeta adds given metadata to this document.

func (*Document) Attribute added in v2.1.6

func (n *Document) Attribute(name string) (text.MultiLineValue, bool)

Attribute implements Node.Attribute.

func (*Document) Attributes added in v2.1.6

func (n *Document) Attributes() []Attribute

Attributes implements Node.Attributes.

func (*Document) Dump

func (n *Document) Dump(_ []byte) *NodeDump

Dump implements Node.Dump .

func (*Document) Kind

func (n *Document) Kind() NodeKind

Kind implements Node.Kind.

func (*Document) Metadata

func (n *Document) Metadata() map[string]any

Metadata returns metadata of this document.

func (*Document) NextSibling added in v2.1.6

func (n *Document) NextSibling() Node

NextSibling implements Node.NextSibling.

func (*Document) OwnerDocument

func (n *Document) OwnerDocument() *Document

OwnerDocument implements Node.OwnerDocument.

func (*Document) Parent added in v2.1.6

func (n *Document) Parent() Node

Parent implements Node.Parent.

func (*Document) Pos

func (n *Document) Pos() int

Pos implements Node.Pos.

func (*Document) PreviousSibling added in v2.1.6

func (n *Document) PreviousSibling() Node

PreviousSibling implements Node.PreviousSibling.

func (*Document) RemoveAttributes added in v2.1.6

func (n *Document) RemoveAttributes()

RemoveAttributes implements Node.RemoveAttributes.

func (*Document) SetAttribute added in v2.1.6

func (n *Document) SetAttribute(name string, value text.MultiLineValue)

SetAttribute implements Node.SetAttribute.

func (*Document) SetMetadata

func (n *Document) SetMetadata(meta map[string]any)

SetMetadata sets given metadata to this document.

func (*Document) SetNextSibling added in v2.1.6

func (n *Document) SetNextSibling(v Node)

SetNextSibling implements Node.SetNextSibling.

func (*Document) SetParent added in v2.1.6

func (n *Document) SetParent(v Node)

SetParent implements Node.SetParent.

func (*Document) SetPreviousSibling added in v2.1.6

func (n *Document) SetPreviousSibling(v Node)

SetPreviousSibling implements Node.SetPreviousSibling.

type Emphasis

type Emphasis struct {
	BaseInline
}

An Emphasis struct represents an emphasis of Markdown text (e.g. *text* or _text_).

func NewEmphasis

func NewEmphasis() *Emphasis

NewEmphasis returns a new Emphasis node.

func (*Emphasis) Attribute added in v2.1.6

func (n *Emphasis) Attribute(name string) (text.MultiLineValue, bool)

Attribute implements Node.Attribute.

func (*Emphasis) Attributes added in v2.1.6

func (n *Emphasis) Attributes() []Attribute

Attributes implements Node.Attributes.

func (*Emphasis) Dump

func (n *Emphasis) Dump(_ []byte) *NodeDump

Dump implements Node.Dump.

func (*Emphasis) Kind

func (n *Emphasis) Kind() NodeKind

Kind implements Node.Kind.

func (*Emphasis) NextSibling added in v2.1.6

func (n *Emphasis) NextSibling() Node

NextSibling implements Node.NextSibling.

func (*Emphasis) Parent added in v2.1.6

func (n *Emphasis) Parent() Node

Parent implements Node.Parent.

func (*Emphasis) PreviousSibling added in v2.1.6

func (n *Emphasis) PreviousSibling() Node

PreviousSibling implements Node.PreviousSibling.

func (*Emphasis) RemoveAttributes added in v2.1.6

func (n *Emphasis) RemoveAttributes()

RemoveAttributes implements Node.RemoveAttributes.

func (*Emphasis) SetAttribute added in v2.1.6

func (n *Emphasis) SetAttribute(name string, value text.MultiLineValue)

SetAttribute implements Node.SetAttribute.

func (*Emphasis) SetNextSibling added in v2.1.6

func (n *Emphasis) SetNextSibling(v Node)

SetNextSibling implements Node.SetNextSibling.

func (*Emphasis) SetParent added in v2.1.6

func (n *Emphasis) SetParent(v Node)

SetParent implements Node.SetParent.

func (*Emphasis) SetPreviousSibling added in v2.1.6

func (n *Emphasis) SetPreviousSibling(v Node)

SetPreviousSibling implements Node.SetPreviousSibling.

type HTMLBlock

type HTMLBlock struct {

	// HTMLBlockKind is the kind of this html block.
	HTMLBlockKind HTMLBlockKind

	// Value holds the raw HTML content of this block for rendering.
	Value text.Lines
	// contains filtered or unexported fields
}

An HTMLBlock struct represents an html block of Markdown text.

func NewHTMLBlock

func NewHTMLBlock(kind HTMLBlockKind) *HTMLBlock

NewHTMLBlock returns a new HTMLBlock node.

func (*HTMLBlock) AppendSource added in v2.1.6

func (b *HTMLBlock) AppendSource(_ text.Segment)

func (*HTMLBlock) Dump

func (n *HTMLBlock) Dump(_ []byte) *NodeDump

Dump implements Node.Dump.

func (*HTMLBlock) HasBlankPreviousLines added in v2.1.6

func (b *HTMLBlock) HasBlankPreviousLines() bool

func (*HTMLBlock) Kind

func (n *HTMLBlock) Kind() NodeKind

Kind implements Node.Kind.

func (*HTMLBlock) Pos added in v2.1.6

func (b *HTMLBlock) Pos() int

func (*HTMLBlock) SetBlankPreviousLines added in v2.1.6

func (b *HTMLBlock) SetBlankPreviousLines(v bool)

func (*HTMLBlock) SetPos added in v2.1.6

func (b *HTMLBlock) SetPos(v int)

func (*HTMLBlock) SetSource added in v2.1.6

func (b *HTMLBlock) SetSource(_ []text.Segment)

func (*HTMLBlock) Source added in v2.1.6

func (b *HTMLBlock) Source() []text.Segment

type HTMLBlockKind

type HTMLBlockKind int

HTMLBlockKind represents the kind of an HTMLBlock. See https://spec.commonmark.org/0.30/#html-blocks

const (
	// HTMLBlockKind1 represents type 1 html blocks.
	HTMLBlockKind1 HTMLBlockKind = iota + 1
	// HTMLBlockKind2 represents type 2 html blocks.
	HTMLBlockKind2
	// HTMLBlockKind3 represents type 3 html blocks.
	HTMLBlockKind3
	// HTMLBlockKind4 represents type 4 html blocks.
	HTMLBlockKind4
	// HTMLBlockKind5 represents type 5 html blocks.
	HTMLBlockKind5
	// HTMLBlockKind6 represents type 6 html blocks.
	HTMLBlockKind6
	// HTMLBlockKind7 represents type 7 html blocks.
	HTMLBlockKind7
)

func (HTMLBlockKind) String

func (k HTMLBlockKind) String() string

String returns a human-readable name of the HTMLBlockKind.

type Heading

type Heading struct {
	BaseBlock
	// Level is the level of this heading.
	// This value is between 1 and 6.
	Level int
	// HeadingKind indicates whether this is an ATX or Setext heading.
	HeadingKind HeadingKind
}

A Heading struct represents headings like SetextHeading and ATXHeading.

func NewHeading

func NewHeading(level int, kind HeadingKind) *Heading

NewHeading returns a new Heading node.

func (*Heading) Attribute added in v2.1.6

func (n *Heading) Attribute(name string) (text.MultiLineValue, bool)

Attribute implements Node.Attribute.

func (*Heading) Attributes added in v2.1.6

func (n *Heading) Attributes() []Attribute

Attributes implements Node.Attributes.

func (*Heading) Dump

func (n *Heading) Dump(_ []byte) *NodeDump

Dump implements Node.Dump .

func (*Heading) Kind

func (n *Heading) Kind() NodeKind

Kind implements Node.Kind.

func (*Heading) NextSibling added in v2.1.6

func (n *Heading) NextSibling() Node

NextSibling implements Node.NextSibling.

func (*Heading) Parent added in v2.1.6

func (n *Heading) Parent() Node

Parent implements Node.Parent.

func (*Heading) PreviousSibling added in v2.1.6

func (n *Heading) PreviousSibling() Node

PreviousSibling implements Node.PreviousSibling.

func (*Heading) RemoveAttributes added in v2.1.6

func (n *Heading) RemoveAttributes()

RemoveAttributes implements Node.RemoveAttributes.

func (*Heading) SetAttribute added in v2.1.6

func (n *Heading) SetAttribute(name string, value text.MultiLineValue)

SetAttribute implements Node.SetAttribute.

func (*Heading) SetNextSibling added in v2.1.6

func (n *Heading) SetNextSibling(v Node)

SetNextSibling implements Node.SetNextSibling.

func (*Heading) SetParent added in v2.1.6

func (n *Heading) SetParent(v Node)

SetParent implements Node.SetParent.

func (*Heading) SetPreviousSibling added in v2.1.6

func (n *Heading) SetPreviousSibling(v Node)

SetPreviousSibling implements Node.SetPreviousSibling.

type HeadingKind

type HeadingKind int

HeadingKind represents the kind of a Heading: ATX or Setext.

const (
	// HeadingKindATX represents an ATX heading (e.g. ## heading).
	HeadingKindATX HeadingKind = iota + 1
	// HeadingKindSetext represents a Setext heading (underline style).
	HeadingKindSetext
)

func (HeadingKind) String

func (k HeadingKind) String() string

String returns a human-readable name of the HeadingKind.

type Image

type Image struct {
	BaseInline

	// Destination is a destination(URL) of this link.
	Destination text.SingleLineValue

	// Title is a title of this link.
	Title text.MultiLineValue

	// Reference is a reference of this link. This field is used for reference links.
	// If this link is not a reference link, this field is nil.
	Reference *ReferenceLink
}

An Image struct represents an image of the Markdown text.

func NewImage

func NewImage(destination text.SingleLineValue, opts ...ImageOption) *Image

NewImage returns a new Image node with the given destination and options.

func (*Image) Attribute added in v2.1.6

func (n *Image) Attribute(name string) (text.MultiLineValue, bool)

Attribute implements Node.Attribute.

func (*Image) Attributes added in v2.1.6

func (n *Image) Attributes() []Attribute

Attributes implements Node.Attributes.

func (*Image) Dump

func (n *Image) Dump(_ []byte) *NodeDump

Dump implements Node.Dump.

func (*Image) Kind

func (n *Image) Kind() NodeKind

Kind implements Node.Kind.

func (*Image) NextSibling added in v2.1.6

func (n *Image) NextSibling() Node

NextSibling implements Node.NextSibling.

func (*Image) Parent added in v2.1.6

func (n *Image) Parent() Node

Parent implements Node.Parent.

func (*Image) PreviousSibling added in v2.1.6

func (n *Image) PreviousSibling() Node

PreviousSibling implements Node.PreviousSibling.

func (*Image) RemoveAttributes added in v2.1.6

func (n *Image) RemoveAttributes()

RemoveAttributes implements Node.RemoveAttributes.

func (*Image) SetAttribute added in v2.1.6

func (n *Image) SetAttribute(name string, value text.MultiLineValue)

SetAttribute implements Node.SetAttribute.

func (*Image) SetNextSibling added in v2.1.6

func (n *Image) SetNextSibling(v Node)

SetNextSibling implements Node.SetNextSibling.

func (*Image) SetParent added in v2.1.6

func (n *Image) SetParent(v Node)

SetParent implements Node.SetParent.

func (*Image) SetPreviousSibling added in v2.1.6

func (n *Image) SetPreviousSibling(v Node)

SetPreviousSibling implements Node.SetPreviousSibling.

type ImageOption added in v2.0.2

type ImageOption interface {
	// contains filtered or unexported methods
}

ImageOption is an option for Image nodes.

type InlineNode

type InlineNode interface {
	Node

	// FirstRune returns the first visible rune of this node's value
	// and true if the node has a visible rune, otherwise false.
	FirstRune(source []byte) (rune, bool)

	// LastRune returns the last visible rune of this node's value
	// and true if the node has a visible rune, otherwise false.
	LastRune(source []byte) (rune, bool)
	// contains filtered or unexported methods
}

An InlineNode interface is a Node that represents an inline element.

type Link struct {
	BaseInline

	// Destination is a destination(URL) of this link.
	Destination text.SingleLineValue

	// Title is a title of this link.
	Title text.MultiLineValue

	// Reference is a reference of this link. This field is used for reference links.
	// If this link is not a reference link, this field is nil.
	Reference *ReferenceLink
}

A Link struct represents a link of the Markdown text.

func NewLink(destination text.SingleLineValue, opts ...LinkOption) *Link

NewLink returns a new Link node with the given destination and options.

func (*Link) Attribute added in v2.1.6

func (n *Link) Attribute(name string) (text.MultiLineValue, bool)

Attribute implements Node.Attribute.

func (*Link) Attributes added in v2.1.6

func (n *Link) Attributes() []Attribute

Attributes implements Node.Attributes.

func (*Link) Dump

func (n *Link) Dump(_ []byte) *NodeDump

Dump implements Node.Dump.

func (*Link) Kind

func (n *Link) Kind() NodeKind

Kind implements Node.Kind.

func (*Link) NextSibling added in v2.1.6

func (n *Link) NextSibling() Node

NextSibling implements Node.NextSibling.

func (*Link) Parent added in v2.1.6

func (n *Link) Parent() Node

Parent implements Node.Parent.

func (*Link) PreviousSibling added in v2.1.6

func (n *Link) PreviousSibling() Node

PreviousSibling implements Node.PreviousSibling.

func (*Link) RemoveAttributes added in v2.1.6

func (n *Link) RemoveAttributes()

RemoveAttributes implements Node.RemoveAttributes.

func (*Link) SetAttribute added in v2.1.6

func (n *Link) SetAttribute(name string, value text.MultiLineValue)

SetAttribute implements Node.SetAttribute.

func (*Link) SetNextSibling added in v2.1.6

func (n *Link) SetNextSibling(v Node)

SetNextSibling implements Node.SetNextSibling.

func (*Link) SetParent added in v2.1.6

func (n *Link) SetParent(v Node)

SetParent implements Node.SetParent.

func (*Link) SetPreviousSibling added in v2.1.6

func (n *Link) SetPreviousSibling(v Node)

SetPreviousSibling implements Node.SetPreviousSibling.

type LinkOption

type LinkOption interface {
	// contains filtered or unexported methods
}

LinkOption is an option for Link and Image nodes.

type LinkReferenceDefinition

type LinkReferenceDefinition struct {

	// Label is a label of this link reference definition.
	Label text.MultiLineValue

	// Destination is a destination of this link reference definition.
	Destination text.SingleLineValue

	// Title is a title of this link reference definition.
	Title text.MultiLineValue
	// contains filtered or unexported fields
}

A LinkReferenceDefinition struct represents a list of Markdown text.

func NewLinkReferenceDefinition

func NewLinkReferenceDefinition(
	label text.MultiLineValue, destination text.SingleLineValue,
	opts ...LinkReferenceDefinitionOption) *LinkReferenceDefinition

NewLinkReferenceDefinition returns a new LinkReferenceDefinition node.

func (*LinkReferenceDefinition) AppendSource added in v2.1.6

func (b *LinkReferenceDefinition) AppendSource(_ text.Segment)

func (*LinkReferenceDefinition) Dump

func (l *LinkReferenceDefinition) Dump(_ []byte) *NodeDump

Dump implements Node.Dump.

func (*LinkReferenceDefinition) HasBlankPreviousLines added in v2.1.6

func (b *LinkReferenceDefinition) HasBlankPreviousLines() bool

func (*LinkReferenceDefinition) Kind

Kind implements Node.Kind.

func (*LinkReferenceDefinition) Pos added in v2.1.6

func (b *LinkReferenceDefinition) Pos() int

func (*LinkReferenceDefinition) SetBlankPreviousLines added in v2.1.6

func (b *LinkReferenceDefinition) SetBlankPreviousLines(v bool)

func (*LinkReferenceDefinition) SetPos added in v2.1.6

func (b *LinkReferenceDefinition) SetPos(v int)

func (*LinkReferenceDefinition) SetSource added in v2.1.6

func (b *LinkReferenceDefinition) SetSource(_ []text.Segment)

func (*LinkReferenceDefinition) Source added in v2.1.6

func (b *LinkReferenceDefinition) Source() []text.Segment

type LinkReferenceDefinitionOption

type LinkReferenceDefinitionOption interface {
	// contains filtered or unexported methods
}

LinkReferenceDefinitionOption is an option for LinkReferenceDefinition nodes.

type List

type List struct {
	BaseBlock

	// Marker is a marker character like '-', '+', ')' and '.'.
	Marker byte

	// IsTight is a true if this list is a 'tight' list.
	// See https://spec.commonmark.org/0.30/#loose for details.
	IsTight bool

	// Start is an initial number of this ordered list.
	// If this list is not an ordered list, Start is 0.
	Start int
}

A List struct represents a list of Markdown text.

func NewList

func NewList(marker byte) *List

NewList returns a new List node.

func (*List) Attribute added in v2.1.6

func (n *List) Attribute(name string) (text.MultiLineValue, bool)

Attribute implements Node.Attribute.

func (*List) Attributes added in v2.1.6

func (n *List) Attributes() []Attribute

Attributes implements Node.Attributes.

func (*List) CanContinue

func (l *List) CanContinue(marker byte, isOrdered bool) bool

CanContinue returns true if this list can continue with the given marker character and orderedness, otherwise false.

func (*List) Dump

func (l *List) Dump(_ []byte) *NodeDump

Dump implements Node.Dump.

func (*List) IsOrdered

func (l *List) IsOrdered() bool

IsOrdered returns true if this list is an ordered list, otherwise false.

func (*List) Kind

func (l *List) Kind() NodeKind

Kind implements Node.Kind.

func (*List) NextSibling added in v2.1.6

func (n *List) NextSibling() Node

NextSibling implements Node.NextSibling.

func (*List) Parent added in v2.1.6

func (n *List) Parent() Node

Parent implements Node.Parent.

func (*List) PreviousSibling added in v2.1.6

func (n *List) PreviousSibling() Node

PreviousSibling implements Node.PreviousSibling.

func (*List) RemoveAttributes added in v2.1.6

func (n *List) RemoveAttributes()

RemoveAttributes implements Node.RemoveAttributes.

func (*List) SetAttribute added in v2.1.6

func (n *List) SetAttribute(name string, value text.MultiLineValue)

SetAttribute implements Node.SetAttribute.

func (*List) SetNextSibling added in v2.1.6

func (n *List) SetNextSibling(v Node)

SetNextSibling implements Node.SetNextSibling.

func (*List) SetParent added in v2.1.6

func (n *List) SetParent(v Node)

SetParent implements Node.SetParent.

func (*List) SetPreviousSibling added in v2.1.6

func (n *List) SetPreviousSibling(v Node)

SetPreviousSibling implements Node.SetPreviousSibling.

type ListItem

type ListItem struct {
	BaseBlock
	// contains filtered or unexported fields
}

A ListItem struct represents a list item of Markdown text.

func NewListItem

func NewListItem() *ListItem

NewListItem returns a new ListItem node.

func (*ListItem) Attribute added in v2.1.6

func (n *ListItem) Attribute(name string) (text.MultiLineValue, bool)

Attribute implements Node.Attribute.

func (*ListItem) Attributes added in v2.1.6

func (n *ListItem) Attributes() []Attribute

Attributes implements Node.Attributes.

func (*ListItem) Dump

func (n *ListItem) Dump(_ []byte) *NodeDump

Dump implements Node.Dump.

func (*ListItem) Kind

func (n *ListItem) Kind() NodeKind

Kind implements Node.Kind.

func (*ListItem) NextSibling added in v2.1.6

func (n *ListItem) NextSibling() Node

NextSibling implements Node.NextSibling.

func (*ListItem) Offset

func (n *ListItem) Offset() int

Offset returns the content indentation offset used during parsing. This is set by the list parser and is not meaningful for programmatic construction.

func (*ListItem) Parent added in v2.1.6

func (n *ListItem) Parent() Node

Parent implements Node.Parent.

func (*ListItem) PreviousSibling added in v2.1.6

func (n *ListItem) PreviousSibling() Node

PreviousSibling implements Node.PreviousSibling.

func (*ListItem) RemoveAttributes added in v2.1.6

func (n *ListItem) RemoveAttributes()

RemoveAttributes implements Node.RemoveAttributes.

func (*ListItem) SetAttribute added in v2.1.6

func (n *ListItem) SetAttribute(name string, value text.MultiLineValue)

SetAttribute implements Node.SetAttribute.

func (*ListItem) SetNextSibling added in v2.1.6

func (n *ListItem) SetNextSibling(v Node)

SetNextSibling implements Node.SetNextSibling.

func (*ListItem) SetOffset

func (n *ListItem) SetOffset(v int)

SetOffset sets the content indentation offset. This is called by the list parser during parsing.

func (*ListItem) SetParent added in v2.1.6

func (n *ListItem) SetParent(v Node)

SetParent implements Node.SetParent.

func (*ListItem) SetPreviousSibling added in v2.1.6

func (n *ListItem) SetPreviousSibling(v Node)

SetPreviousSibling implements Node.SetPreviousSibling.

type Node

type Node interface {
	// Kind returns a kind of this node.
	Kind() NodeKind

	// Pos returns a position of this node in a source.
	// If this node position is not defined, Pos returns -1.
	Pos() int

	// SetPos sets a position of this node in a source.
	// Some node may ignore this method. For example, Paragraph node ignores this method because
	// it calculates its position from its lines.
	SetPos(v int)

	// NextSibling returns a next sibling node of this node.
	NextSibling() Node

	// PreviousSibling returns a previous sibling node of this node.
	PreviousSibling() Node

	// Parent returns a parent node of this node.
	Parent() Node

	// SetParent sets a parent node to this node.
	SetParent(Node)

	// SetPreviousSibling sets a previous sibling node to this node.
	SetPreviousSibling(Node)

	// SetNextSibling sets a next sibling node to this node.
	SetNextSibling(Node)

	// HasChildren returns true if this node has any children, otherwise false.
	HasChildren() bool

	// ChildCount returns a total number of children.
	ChildCount() int

	// Children returns an iterator of children of this node.
	Children() iter.Seq[Node]

	// FirstChild returns a first child of this node.
	FirstChild() Node

	// LastChild returns a last child of this node.
	LastChild() Node

	// AppendChild append a node child to the tail of the children.
	AppendChild(child Node)

	// RemoveChild removes a node child from this node.
	// If a node child is not children of this node, RemoveChild nothing to do.
	RemoveChild(child Node)

	// RemoveChildren removes all children from this node.
	RemoveChildren()

	// ReplaceChild replaces a node target with a node insertee.
	// If target is not a child of this node, ReplaceChild appends insertee to the
	// tail of the children.
	ReplaceChild(target, insertee Node)

	// InsertBefore inserts a node insertee before a node target.
	// If target is not a child of this node, InsertBefore appends insertee to the
	// tail of the children.
	InsertBefore(target, insertee Node)

	// InsertAfter inserts a node insertee after a node target.
	// If target is not a child of this node, InsertAfter appends insertee to the
	// tail of the children.
	InsertAfter(target, insertee Node)

	// OwnerDocument returns this node's owner document.
	// If this node is not a child of the Document node, OwnerDocument
	// returns nil.
	OwnerDocument() *Document

	// Dump dumps an AST node.
	Dump(source []byte) *NodeDump

	// SetAttribute sets the given value to the attributes.
	SetAttribute(name string, value text.MultiLineValue)

	// Attribute returns a (attribute value, true) if an attribute
	// associated with the given name is found, otherwise
	// (zero MultiLineValue, false)
	Attribute(name string) (text.MultiLineValue, bool)

	// Attributes returns a list of attributes.
	// This may be a nil if there are no attributes.
	Attributes() []Attribute

	// RemoveAttributes removes all attributes from this node.
	RemoveAttributes()
}

A Node interface defines basic AST node functionalities.

func N

func N(node Node, children ...any) Node

N is a helper function to create a new node with children.

Children must be a Node or a string. If a child is a string, N creates a Text node with the string and append it to the children. Given string must be a decoded string:

- Good: `N(NewParagraph(), "Hello, World!")` - Bad: `N(NewParagraph(), "Hello, World&#33;")`

N panics if a child is not a Node or a string.

type NodeDump

type NodeDump struct {
	// Node is the node to be dumped.
	Node Node

	// Properties is a map of additional properties to be dumped.
	// Property names should be PascalCase.
	Properties map[string]any
}

NodeDump is a struct that holds information for dumping a node.

func NewNodeDump

func NewNodeDump(node Node, properties map[string]any) *NodeDump

NewNodeDump returns a new NodeDump.

func (*NodeDump) Children

func (d *NodeDump) Children(source []byte) iter.Seq[*NodeDump]

Children returns an iterator of children of this node dump.

func (*NodeDump) PrettyPrint

func (d *NodeDump) PrettyPrint(w io.Writer, source []byte, opts ...PrettyPrintOption) error

PrettyPrint pretty prints this node dump to the given writer.

PrettyPrint format may change in the future. Do not rely on the format. This method is intended for debugging purpose only. The returned error is from the writer. If the writer never returns an error, the returned error is always nil.

type NodeKind

type NodeKind int

NodeKind identifies the concrete type of a Node.

var CurrentKindValue NodeKind

CurrentKindValue is the current value of NodeKind.

You **MUST NOT** use this value. This value is public for the goldmark internal package to use.

func NewNodeKind

func NewNodeKind(name string) NodeKind

NewNodeKind returns a new Kind value.

func (NodeKind) String

func (k NodeKind) String() string

type Paragraph

type Paragraph struct {
	BaseBlock
}

A Paragraph struct represents a paragraph of Markdown text.

func NewParagraph

func NewParagraph() *Paragraph

NewParagraph returns a new Paragraph node.

func (*Paragraph) Attribute added in v2.1.6

func (n *Paragraph) Attribute(name string) (text.MultiLineValue, bool)

Attribute implements Node.Attribute.

func (*Paragraph) Attributes added in v2.1.6

func (n *Paragraph) Attributes() []Attribute

Attributes implements Node.Attributes.

func (*Paragraph) Dump

func (n *Paragraph) Dump(_ []byte) *NodeDump

Dump implements Node.Dump .

func (*Paragraph) Kind

func (n *Paragraph) Kind() NodeKind

Kind implements Node.Kind.

func (*Paragraph) NextSibling added in v2.1.6

func (n *Paragraph) NextSibling() Node

NextSibling implements Node.NextSibling.

func (*Paragraph) Parent added in v2.1.6

func (n *Paragraph) Parent() Node

Parent implements Node.Parent.

func (*Paragraph) Pos

func (n *Paragraph) Pos() int

Pos implements Node.Pos.

func (*Paragraph) PreviousSibling added in v2.1.6

func (n *Paragraph) PreviousSibling() Node

PreviousSibling implements Node.PreviousSibling.

func (*Paragraph) RemoveAttributes added in v2.1.6

func (n *Paragraph) RemoveAttributes()

RemoveAttributes implements Node.RemoveAttributes.

func (*Paragraph) SetAttribute added in v2.1.6

func (n *Paragraph) SetAttribute(name string, value text.MultiLineValue)

SetAttribute implements Node.SetAttribute.

func (*Paragraph) SetNextSibling added in v2.1.6

func (n *Paragraph) SetNextSibling(v Node)

SetNextSibling implements Node.SetNextSibling.

func (*Paragraph) SetParent added in v2.1.6

func (n *Paragraph) SetParent(v Node)

SetParent implements Node.SetParent.

func (*Paragraph) SetPreviousSibling added in v2.1.6

func (n *Paragraph) SetPreviousSibling(v Node)

SetPreviousSibling implements Node.SetPreviousSibling.

type PrettyPrintOption

type PrettyPrintOption func(*ppCfg)

PrettyPrintOption is a function that modifies the configuration of PrettyPrint.

func WithLevel

func WithLevel(level int) PrettyPrintOption

WithLevel returns an option that sets the indentation level for PrettyPrint.

func WithSource

func WithSource(include bool) PrettyPrintOption

WithSource returns an option that sets whether to include the source text in the PrettyPrint output.

type RawHTML

type RawHTML struct {

	// Value holds the raw HTML content.
	Value text.MultiLineValue
	// contains filtered or unexported fields
}

A RawHTML struct represents an inline raw HTML of the Markdown text.

func NewRawHTML

func NewRawHTML(value text.MultiLineValue) *RawHTML

NewRawHTML returns a new RawHTML node with the given value.

func (*RawHTML) AppendChild added in v2.1.6

func (n *RawHTML) AppendChild(_ Node)

AppendChild implements Node.AppendChild.

func (*RawHTML) Attribute added in v2.1.6

func (n *RawHTML) Attribute(name string) (text.MultiLineValue, bool)

Attribute implements Node.Attribute.

func (*RawHTML) Attributes added in v2.1.6

func (n *RawHTML) Attributes() []Attribute

Attributes implements Node.Attributes.

func (*RawHTML) ChildCount added in v2.1.6

func (n *RawHTML) ChildCount() int

ChildCount implements Node.ChildCount.

func (*RawHTML) Children added in v2.1.6

func (n *RawHTML) Children() iter.Seq[Node]

Children implements Node.Children.

func (*RawHTML) Dump

func (n *RawHTML) Dump(_ []byte) *NodeDump

Dump implements Node.Dump.

func (*RawHTML) FirstChild added in v2.1.6

func (n *RawHTML) FirstChild() Node

FirstChild implements Node.FirstChild.

func (*RawHTML) FirstRune added in v2.1.6

func (n *RawHTML) FirstRune(_ []byte) (rune, bool)

FirstRune implements InlineNode.FirstRune.

func (*RawHTML) HasChildren added in v2.1.6

func (n *RawHTML) HasChildren() bool

HasChildren implements Node.HasChildren.

func (*RawHTML) InsertAfter added in v2.1.6

func (n *RawHTML) InsertAfter(_ Node, _ Node)

InsertAfter implements Node.InsertAfter.

func (*RawHTML) InsertBefore added in v2.1.6

func (n *RawHTML) InsertBefore(_ Node, _ Node)

InsertBefore implements Node.InsertBefore.

func (*RawHTML) Kind

func (n *RawHTML) Kind() NodeKind

Kind implements Node.Kind.

func (*RawHTML) LastChild added in v2.1.6

func (n *RawHTML) LastChild() Node

LastChild implements Node.LastChild.

func (*RawHTML) LastRune added in v2.1.6

func (n *RawHTML) LastRune(_ []byte) (rune, bool)

LastRune implements InlineNode.LastRune.

func (*RawHTML) NextSibling added in v2.1.6

func (n *RawHTML) NextSibling() Node

NextSibling implements Node.NextSibling.

func (*RawHTML) OwnerDocument added in v2.1.6

func (n *RawHTML) OwnerDocument() *Document

OwnerDocument implements Node.OwnerDocument.

func (*RawHTML) Parent added in v2.1.6

func (n *RawHTML) Parent() Node

Parent implements Node.Parent.

func (*RawHTML) Pos added in v2.1.6

func (n *RawHTML) Pos() int

Pos implements Node.Pos.

func (*RawHTML) PreviousSibling added in v2.1.6

func (n *RawHTML) PreviousSibling() Node

PreviousSibling implements Node.PreviousSibling.

func (*RawHTML) RemoveAttributes added in v2.1.6

func (n *RawHTML) RemoveAttributes()

RemoveAttributes implements Node.RemoveAttributes.

func (*RawHTML) RemoveChild added in v2.1.6

func (n *RawHTML) RemoveChild(_ Node)

RemoveChild implements Node.RemoveChild.

func (*RawHTML) RemoveChildren added in v2.1.6

func (n *RawHTML) RemoveChildren()

RemoveChildren implements Node.RemoveChildren.

func (*RawHTML) ReplaceChild added in v2.1.6

func (n *RawHTML) ReplaceChild(_ Node, _ Node)

ReplaceChild implements Node.ReplaceChild.

func (*RawHTML) SetAttribute added in v2.1.6

func (n *RawHTML) SetAttribute(name string, value text.MultiLineValue)

SetAttribute implements Node.SetAttribute.

func (*RawHTML) SetNextSibling added in v2.1.6

func (n *RawHTML) SetNextSibling(v Node)

SetNextSibling implements Node.SetNextSibling.

func (*RawHTML) SetParent added in v2.1.6

func (n *RawHTML) SetParent(v Node)

SetParent implements Node.SetParent.

func (*RawHTML) SetPos added in v2.1.6

func (n *RawHTML) SetPos(_ int)

SetPos implements Node.SetPos.

func (*RawHTML) SetPreviousSibling added in v2.1.6

func (n *RawHTML) SetPreviousSibling(v Node)

SetPreviousSibling implements Node.SetPreviousSibling.

type ReferenceLink struct {
	// ReferenceLinkKind is the kind of this reference link.
	ReferenceLinkKind ReferenceLinkKind

	// Value is a value of this reference link.
	Value text.MultiLineValue
}

ReferenceLink struct represents a reference link of the Markdown text.

func NewReferenceLink(kind ReferenceLinkKind, value text.MultiLineValue) *ReferenceLink

NewReferenceLink returns a new ReferenceLink with the given kind and value.

type ReferenceLinkKind

type ReferenceLinkKind int

ReferenceLinkKind represents the kind of a reference link.

const (
	// ReferenceLinkKindFull indicates that a reference link has a full reference like [foo][bar].
	ReferenceLinkKindFull ReferenceLinkKind = iota + 1
	// ReferenceLinkKindCollapsed indicates that a reference link has a collapsed reference like [foo][].
	ReferenceLinkKindCollapsed
	// ReferenceLinkKindShortcut indicates that a reference link has a shortcut reference like [foo].
	ReferenceLinkKindShortcut
)

func (ReferenceLinkKind) String

func (t ReferenceLinkKind) String() string

String returns a string representation of this reference link kind.

type Strong

type Strong struct {
	BaseInline
}

A Strong struct represents strong importance of Markdown text (e.g. **text** or __text__).

func NewStrong

func NewStrong() *Strong

NewStrong returns a new Strong node.

func (*Strong) Attribute added in v2.1.6

func (n *Strong) Attribute(name string) (text.MultiLineValue, bool)

Attribute implements Node.Attribute.

func (*Strong) Attributes added in v2.1.6

func (n *Strong) Attributes() []Attribute

Attributes implements Node.Attributes.

func (*Strong) Dump

func (n *Strong) Dump(_ []byte) *NodeDump

Dump implements Node.Dump.

func (*Strong) Kind

func (n *Strong) Kind() NodeKind

Kind implements Node.Kind.

func (*Strong) NextSibling added in v2.1.6

func (n *Strong) NextSibling() Node

NextSibling implements Node.NextSibling.

func (*Strong) Parent added in v2.1.6

func (n *Strong) Parent() Node

Parent implements Node.Parent.

func (*Strong) PreviousSibling added in v2.1.6

func (n *Strong) PreviousSibling() Node

PreviousSibling implements Node.PreviousSibling.

func (*Strong) RemoveAttributes added in v2.1.6

func (n *Strong) RemoveAttributes()

RemoveAttributes implements Node.RemoveAttributes.

func (*Strong) SetAttribute added in v2.1.6

func (n *Strong) SetAttribute(name string, value text.MultiLineValue)

SetAttribute implements Node.SetAttribute.

func (*Strong) SetNextSibling added in v2.1.6

func (n *Strong) SetNextSibling(v Node)

SetNextSibling implements Node.SetNextSibling.

func (*Strong) SetParent added in v2.1.6

func (n *Strong) SetParent(v Node)

SetParent implements Node.SetParent.

func (*Strong) SetPreviousSibling added in v2.1.6

func (n *Strong) SetPreviousSibling(v Node)

SetPreviousSibling implements Node.SetPreviousSibling.

type Text

type Text struct {

	// Value is the text value. It is either a source position or an owned string.
	Value text.SingleLineValue
	// contains filtered or unexported fields
}

A Text struct represents a textual content of the Markdown text.

func NewText

func NewText(value text.SingleLineValue) *Text

NewText returns a new Text node.

func (*Text) AppendChild added in v2.1.6

func (n *Text) AppendChild(_ Node)

AppendChild implements Node.AppendChild.

func (*Text) Attribute added in v2.1.6

func (n *Text) Attribute(name string) (text.MultiLineValue, bool)

Attribute implements Node.Attribute.

func (*Text) Attributes added in v2.1.6

func (n *Text) Attributes() []Attribute

Attributes implements Node.Attributes.

func (*Text) ChildCount added in v2.1.6

func (n *Text) ChildCount() int

ChildCount implements Node.ChildCount.

func (*Text) Children added in v2.1.6

func (n *Text) Children() iter.Seq[Node]

Children implements Node.Children.

func (*Text) Dump

func (n *Text) Dump(_ []byte) *NodeDump

Dump implements Node.Dump.

func (*Text) FirstChild added in v2.1.6

func (n *Text) FirstChild() Node

FirstChild implements Node.FirstChild.

func (*Text) FirstRune added in v2.1.6

func (n *Text) FirstRune(source []byte) (rune, bool)

FirstRune implements InlineNode.FirstRune.

func (*Text) HardLineBreak

func (n *Text) HardLineBreak() bool

HardLineBreak returns true if this node ends with a hard line break. See https://spec.commonmark.org/0.30/#hard-line-breaks for details.

func (*Text) HasChildren added in v2.1.6

func (n *Text) HasChildren() bool

HasChildren implements Node.HasChildren.

func (*Text) InsertAfter added in v2.1.6

func (n *Text) InsertAfter(_ Node, _ Node)

InsertAfter implements Node.InsertAfter.

func (*Text) InsertBefore added in v2.1.6

func (n *Text) InsertBefore(_ Node, _ Node)

InsertBefore implements Node.InsertBefore.

func (*Text) Kind

func (n *Text) Kind() NodeKind

Kind implements Node.Kind.

func (*Text) LastChild added in v2.1.6

func (n *Text) LastChild() Node

LastChild implements Node.LastChild.

func (*Text) LastRune added in v2.1.6

func (n *Text) LastRune(source []byte) (rune, bool)

LastRune implements InlineNode.LastRune.

func (*Text) NextSibling added in v2.1.6

func (n *Text) NextSibling() Node

NextSibling implements Node.NextSibling.

func (*Text) OwnerDocument added in v2.1.6

func (n *Text) OwnerDocument() *Document

OwnerDocument implements Node.OwnerDocument.

func (*Text) Parent added in v2.1.6

func (n *Text) Parent() Node

Parent implements Node.Parent.

func (*Text) Pos

func (n *Text) Pos() int

Pos implements Node.Pos.

func (*Text) PreviousSibling added in v2.1.6

func (n *Text) PreviousSibling() Node

PreviousSibling implements Node.PreviousSibling.

func (*Text) RemoveAttributes added in v2.1.6

func (n *Text) RemoveAttributes()

RemoveAttributes implements Node.RemoveAttributes.

func (*Text) RemoveChild added in v2.1.6

func (n *Text) RemoveChild(_ Node)

RemoveChild implements Node.RemoveChild.

func (*Text) RemoveChildren added in v2.1.6

func (n *Text) RemoveChildren()

RemoveChildren implements Node.RemoveChildren.

func (*Text) ReplaceChild added in v2.1.6

func (n *Text) ReplaceChild(_ Node, _ Node)

ReplaceChild implements Node.ReplaceChild.

func (*Text) SetAttribute added in v2.1.6

func (n *Text) SetAttribute(name string, value text.MultiLineValue)

SetAttribute implements Node.SetAttribute.

func (*Text) SetHardLineBreak

func (n *Text) SetHardLineBreak(v bool)

SetHardLineBreak sets whether this node ends with a hard line break.

func (*Text) SetNextSibling added in v2.1.6

func (n *Text) SetNextSibling(v Node)

SetNextSibling implements Node.SetNextSibling.

func (*Text) SetParent added in v2.1.6

func (n *Text) SetParent(v Node)

SetParent implements Node.SetParent.

func (*Text) SetPos added in v2.1.6

func (n *Text) SetPos(_ int)

SetPos implements Node.SetPos.

func (*Text) SetPreviousSibling added in v2.1.6

func (n *Text) SetPreviousSibling(v Node)

SetPreviousSibling implements Node.SetPreviousSibling.

func (*Text) SetSoftLineBreak

func (n *Text) SetSoftLineBreak(v bool)

SetSoftLineBreak sets whether this node ends with a new line.

func (*Text) SoftLineBreak

func (n *Text) SoftLineBreak() bool

SoftLineBreak returns true if this node ends with a new line, otherwise false.

type ThematicBreak

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

A ThematicBreak struct represents a thematic break of Markdown text.

func NewThematicBreak

func NewThematicBreak() *ThematicBreak

NewThematicBreak returns a new ThematicBreak node.

func (*ThematicBreak) AppendSource added in v2.1.6

func (b *ThematicBreak) AppendSource(_ text.Segment)

func (*ThematicBreak) Dump

func (n *ThematicBreak) Dump(_ []byte) *NodeDump

Dump implements Node.Dump .

func (*ThematicBreak) HasBlankPreviousLines added in v2.1.6

func (b *ThematicBreak) HasBlankPreviousLines() bool

func (*ThematicBreak) Kind

func (n *ThematicBreak) Kind() NodeKind

Kind implements Node.Kind.

func (*ThematicBreak) Pos added in v2.1.6

func (b *ThematicBreak) Pos() int

func (*ThematicBreak) SetBlankPreviousLines added in v2.1.6

func (b *ThematicBreak) SetBlankPreviousLines(v bool)

func (*ThematicBreak) SetPos added in v2.1.6

func (b *ThematicBreak) SetPos(v int)

func (*ThematicBreak) SetSource added in v2.1.6

func (b *ThematicBreak) SetSource(_ []text.Segment)

func (*ThematicBreak) Source added in v2.1.6

func (b *ThematicBreak) Source() []text.Segment

type WalkStatus

type WalkStatus int

WalkStatus represents a current status of the Walk function.

const (
	// WalkStop indicates no more walking needed.
	WalkStop WalkStatus = iota + 1

	// WalkSkipChildren indicates that Walk will not walk on children of the current
	// node.
	WalkSkipChildren

	// WalkContinue indicates that Walk can continue to walk.
	WalkContinue
)

type Walker

type Walker func(n Node, entering bool) (WalkStatus, error)

Walker is a function that will be called when Walk find a new node. entering is set true before walks children, false after walked children. If Walker returns error, Walk function immediately stop walking.

Jump to

Keyboard shortcuts

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