...

Package ast

import "github.com/yuin/goldmark/ast"
Overview
Index

Overview ▾

Package ast defines AST nodes that represent markdown elements.

Index ▾

Variables
func DumpHelper(v Node, source []byte, level int, kv map[string]string, cb func(int))
func IsParagraph(node Node) bool
func MergeOrAppendTextSegment(parent Node, s textm.Segment)
func MergeOrReplaceTextSegment(parent Node, n Node, s textm.Segment)
func Walk(n Node, walker Walker) error
type Attribute
type AutoLink
    func NewAutoLink(typ AutoLinkType, value *Text) *AutoLink
    func (n *AutoLink) Dump(source []byte, level int)
    func (n *AutoLink) Inline()
    func (n *AutoLink) Kind() NodeKind
    func (n *AutoLink) Label(source []byte) []byte
    func (n *AutoLink) URL(source []byte) []byte
type AutoLinkType
type BaseBlock
    func (b *BaseBlock) HasBlankPreviousLines() bool
    func (b *BaseBlock) IsRaw() bool
    func (b *BaseBlock) Lines() *textm.Segments
    func (b *BaseBlock) SetBlankPreviousLines(v bool)
    func (b *BaseBlock) SetLines(v *textm.Segments)
    func (b *BaseBlock) Type() NodeType
type BaseInline
    func (b *BaseInline) HasBlankPreviousLines() bool
    func (b *BaseInline) IsRaw() bool
    func (b *BaseInline) Lines() *textm.Segments
    func (b *BaseInline) SetBlankPreviousLines(v bool)
    func (b *BaseInline) SetLines(v *textm.Segments)
    func (b *BaseInline) Type() NodeType
type BaseNode
    func (n *BaseNode) AppendChild(self, v Node)
    func (n *BaseNode) Attribute(name []byte) (interface{}, bool)
    func (n *BaseNode) AttributeString(s string) (interface{}, bool)
    func (n *BaseNode) Attributes() []Attribute
    func (n *BaseNode) ChildCount() int
    func (n *BaseNode) FirstChild() Node
    func (n *BaseNode) HasChildren() bool
    func (n *BaseNode) InsertAfter(self, v1, insertee Node)
    func (n *BaseNode) InsertBefore(self, v1, insertee Node)
    func (n *BaseNode) LastChild() Node
    func (n *BaseNode) NextSibling() Node
    func (n *BaseNode) OwnerDocument() *Document
    func (n *BaseNode) Parent() Node
    func (n *BaseNode) PreviousSibling() Node
    func (n *BaseNode) RemoveAttributes()
    func (n *BaseNode) RemoveChild(self, v Node)
    func (n *BaseNode) RemoveChildren(self Node)
    func (n *BaseNode) ReplaceChild(self, v1, insertee Node)
    func (n *BaseNode) SetAttribute(name []byte, value interface{})
    func (n *BaseNode) SetAttributeString(name string, value interface{})
    func (n *BaseNode) SetNextSibling(v Node)
    func (n *BaseNode) SetParent(v Node)
    func (n *BaseNode) SetPreviousSibling(v Node)
    func (n *BaseNode) SortChildren(comparator func(n1, n2 Node) int)
    func (n *BaseNode) Text(source []byte) []byte
type Blockquote
    func NewBlockquote() *Blockquote
    func (n *Blockquote) Dump(source []byte, level int)
    func (n *Blockquote) Kind() NodeKind
type CodeBlock
    func NewCodeBlock() *CodeBlock
    func (n *CodeBlock) Dump(source []byte, level int)
    func (n *CodeBlock) IsRaw() bool
    func (n *CodeBlock) Kind() NodeKind
type CodeSpan
    func NewCodeSpan() *CodeSpan
    func (n *CodeSpan) Dump(source []byte, level int)
    func (n *CodeSpan) Inline()
    func (n *CodeSpan) IsBlank(source []byte) bool
    func (n *CodeSpan) Kind() NodeKind
type Document
    func NewDocument() *Document
    func (n *Document) AddMeta(key string, value interface{})
    func (n *Document) Dump(source []byte, level int)
    func (n *Document) Kind() NodeKind
    func (n *Document) Meta() map[string]interface{}
    func (n *Document) OwnerDocument() *Document
    func (n *Document) SetMeta(meta map[string]interface{})
    func (n *Document) Type() NodeType
type Emphasis
    func NewEmphasis(level int) *Emphasis
    func (n *Emphasis) Dump(source []byte, level int)
    func (n *Emphasis) Kind() NodeKind
type FencedCodeBlock
    func NewFencedCodeBlock(info *Text) *FencedCodeBlock
    func (n *FencedCodeBlock) Dump(source []byte, level int)
    func (n *FencedCodeBlock) IsRaw() bool
    func (n *FencedCodeBlock) Kind() NodeKind
    func (n *FencedCodeBlock) Language(source []byte) []byte
type HTMLBlock
    func NewHTMLBlock(typ HTMLBlockType) *HTMLBlock
    func (n *HTMLBlock) Dump(source []byte, level int)
    func (n *HTMLBlock) HasClosure() bool
    func (n *HTMLBlock) IsRaw() bool
    func (n *HTMLBlock) Kind() NodeKind
type HTMLBlockType
type Heading
    func NewHeading(level int) *Heading
    func (n *Heading) Dump(source []byte, level int)
    func (n *Heading) Kind() NodeKind
type Image
    func NewImage(link *Link) *Image
    func (n *Image) Dump(source []byte, level int)
    func (n *Image) Inline()
    func (n *Image) Kind() NodeKind
type Link
    func NewLink() *Link
    func (n *Link) Dump(source []byte, level int)
    func (n *Link) Inline()
    func (n *Link) Kind() NodeKind
type List
    func NewList(marker byte) *List
    func (l *List) CanContinue(marker byte, isOrdered bool) bool
    func (l *List) Dump(source []byte, level int)
    func (l *List) IsOrdered() bool
    func (l *List) Kind() NodeKind
type ListItem
    func NewListItem(offset int) *ListItem
    func (n *ListItem) Dump(source []byte, level int)
    func (n *ListItem) Kind() NodeKind
type Node
type NodeKind
    func NewNodeKind(name string) NodeKind
    func (k NodeKind) String() string
type NodeType
type Paragraph
    func NewParagraph() *Paragraph
    func (n *Paragraph) Dump(source []byte, level int)
    func (n *Paragraph) Kind() NodeKind
type RawHTML
    func NewRawHTML() *RawHTML
    func (n *RawHTML) Dump(source []byte, level int)
    func (n *RawHTML) Inline()
    func (n *RawHTML) Kind() NodeKind
type String
    func NewString(v []byte) *String
    func (n *String) Dump(source []byte, level int)
    func (n *String) Inline()
    func (n *String) IsCode() bool
    func (n *String) IsRaw() bool
    func (n *String) Kind() NodeKind
    func (n *String) SetCode(v bool)
    func (n *String) SetRaw(v bool)
    func (n *String) Text(source []byte) []byte
type Text
    func NewRawTextSegment(v textm.Segment) *Text
    func NewText() *Text
    func NewTextSegment(v textm.Segment) *Text
    func (n *Text) Dump(source []byte, level int)
    func (n *Text) HardLineBreak() bool
    func (n *Text) Inline()
    func (n *Text) IsRaw() bool
    func (n *Text) Kind() NodeKind
    func (n *Text) Merge(node Node, source []byte) bool
    func (n *Text) SetHardLineBreak(v bool)
    func (n *Text) SetRaw(v bool)
    func (n *Text) SetSoftLineBreak(v bool)
    func (n *Text) SoftLineBreak() bool
    func (n *Text) Text(source []byte) []byte
type TextBlock
    func NewTextBlock() *TextBlock
    func (n *TextBlock) Dump(source []byte, level int)
    func (n *TextBlock) Kind() NodeKind
type ThematicBreak
    func NewThematicBreak() *ThematicBreak
    func (n *ThematicBreak) Dump(source []byte, level int)
    func (n *ThematicBreak) Kind() NodeKind
type WalkStatus
type Walker

Package files

ast.go block.go inline.go

Variables

KindAutoLink is a NodeKind of the AutoLink node.

var KindAutoLink = NewNodeKind("AutoLink")

KindBlockquote is a NodeKind of the Blockquote node.

var KindBlockquote = NewNodeKind("Blockquote")

KindCodeBlock is a NodeKind of the CodeBlock node.

var KindCodeBlock = NewNodeKind("CodeBlock")

KindCodeSpan is a NodeKind of the CodeSpan node.

var KindCodeSpan = NewNodeKind("CodeSpan")

KindDocument is a NodeKind of the Document node.

var KindDocument = NewNodeKind("Document")

KindEmphasis is a NodeKind of the Emphasis node.

var KindEmphasis = NewNodeKind("Emphasis")

KindFencedCodeBlock is a NodeKind of the FencedCodeBlock node.

var KindFencedCodeBlock = NewNodeKind("FencedCodeBlock")

KindHTMLBlock is a NodeKind of the HTMLBlock node.

var KindHTMLBlock = NewNodeKind("HTMLBlock")

KindHeading is a NodeKind of the Heading node.

var KindHeading = NewNodeKind("Heading")

KindImage is a NodeKind of the Image node.

var KindImage = NewNodeKind("Image")

KindLink is a NodeKind of the Link node.

var KindLink = NewNodeKind("Link")

KindList is a NodeKind of the List node.

var KindList = NewNodeKind("List")

KindListItem is a NodeKind of the ListItem node.

var KindListItem = NewNodeKind("ListItem")

KindParagraph is a NodeKind of the Paragraph node.

var KindParagraph = NewNodeKind("Paragraph")

KindRawHTML is a NodeKind of the RawHTML node.

var KindRawHTML = NewNodeKind("RawHTML")

KindString is a NodeKind of the String node.

var KindString = NewNodeKind("String")

KindText is a NodeKind of the Text node.

var KindText = NewNodeKind("Text")

KindTextBlock is a NodeKind of the TextBlock node.

var KindTextBlock = NewNodeKind("TextBlock")

KindThematicBreak is a NodeKind of the ThematicBreak node.

var KindThematicBreak = NewNodeKind("ThematicBreak")

func DumpHelper

func DumpHelper(v Node, source []byte, level int, kv map[string]string, cb func(int))

DumpHelper is a helper function to implement Node.Dump. kv is pairs of an attribute name and an attribute value. cb is a function called after wrote a name and attributes.

func IsParagraph

func IsParagraph(node Node) bool

IsParagraph returns true if the given node implements the Paragraph interface, otherwise false.

func MergeOrAppendTextSegment

func MergeOrAppendTextSegment(parent Node, s textm.Segment)

MergeOrAppendTextSegment merges a given s into the last child of the parent if it can be merged, otherwise creates a new Text node and appends it to after current last child.

func MergeOrReplaceTextSegment

func MergeOrReplaceTextSegment(parent Node, n Node, s textm.Segment)

MergeOrReplaceTextSegment merges a given s into a previous sibling of the node n if a previous sibling of the node n is *Text, otherwise replaces Node n with s.

func Walk

func Walk(n Node, walker Walker) error

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

type Attribute

An Attribute is an attribute of the Node

type Attribute struct {
    Name  []byte
    Value interface{}
}

An AutoLink struct represents an autolink of the Markdown text.

type AutoLink struct {
    BaseInline
    // Type is a type of this autolink.
    AutoLinkType AutoLinkType

    // Protocol specified a protocol of the link.
    Protocol []byte
    // contains filtered or unexported fields
}
func NewAutoLink(typ AutoLinkType, value *Text) *AutoLink

NewAutoLink returns a new AutoLink node.

func (*AutoLink) Dump

func (n *AutoLink) Dump(source []byte, level int)

Dump implements Node.Dump

func (*AutoLink) Inline

func (n *AutoLink) Inline()

Inline implements Inline.Inline.

func (*AutoLink) Kind

func (n *AutoLink) Kind() NodeKind

Kind implements Node.Kind.

func (*AutoLink) Label

func (n *AutoLink) Label(source []byte) []byte

Label returns a label of this node.

func (*AutoLink) URL

func (n *AutoLink) URL(source []byte) []byte

URL returns an url of this node.

type AutoLinkType

AutoLinkType defines kind of auto links.

type AutoLinkType int
const (
    // AutoLinkEmail indicates that an autolink is an email address.
    AutoLinkEmail AutoLinkType = iota + 1
    // AutoLinkURL indicates that an autolink is a generic URL.
    AutoLinkURL
)

type BaseBlock

A BaseBlock struct implements the Node interface partialliy.

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

func (*BaseBlock) HasBlankPreviousLines

func (b *BaseBlock) HasBlankPreviousLines() bool

HasBlankPreviousLines implements Node.HasBlankPreviousLines.

func (*BaseBlock) IsRaw

func (b *BaseBlock) IsRaw() bool

IsRaw implements Node.IsRaw

func (*BaseBlock) Lines

func (b *BaseBlock) Lines() *textm.Segments

Lines implements Node.Lines

func (*BaseBlock) SetBlankPreviousLines

func (b *BaseBlock) SetBlankPreviousLines(v bool)

SetBlankPreviousLines implements Node.SetBlankPreviousLines.

func (*BaseBlock) SetLines

func (b *BaseBlock) SetLines(v *textm.Segments)

SetLines implements Node.SetLines

func (*BaseBlock) Type

func (b *BaseBlock) Type() NodeType

Type implements Node.Type

type BaseInline

A BaseInline struct implements the Node interface partialliy.

type BaseInline struct {
    BaseNode
}

func (*BaseInline) HasBlankPreviousLines

func (b *BaseInline) HasBlankPreviousLines() bool

HasBlankPreviousLines implements Node.HasBlankPreviousLines.

func (*BaseInline) IsRaw

func (b *BaseInline) IsRaw() bool

IsRaw implements Node.IsRaw

func (*BaseInline) Lines

func (b *BaseInline) Lines() *textm.Segments

Lines implements Node.Lines

func (*BaseInline) SetBlankPreviousLines

func (b *BaseInline) SetBlankPreviousLines(v bool)

SetBlankPreviousLines implements Node.SetBlankPreviousLines.

func (*BaseInline) SetLines

func (b *BaseInline) SetLines(v *textm.Segments)

SetLines implements Node.SetLines

func (*BaseInline) Type

func (b *BaseInline) Type() NodeType

Type implements Node.Type

type BaseNode

A BaseNode struct implements the Node interface partialliy.

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

func (*BaseNode) AppendChild

func (n *BaseNode) AppendChild(self, v Node)

AppendChild implements Node.AppendChild .

func (*BaseNode) Attribute

func (n *BaseNode) Attribute(name []byte) (interface{}, bool)

Attribute implements Node.Attribute.

func (*BaseNode) AttributeString

func (n *BaseNode) AttributeString(s string) (interface{}, bool)

AttributeString implements Node.AttributeString.

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) FirstChild

func (n *BaseNode) FirstChild() Node

FirstChild implements Node.FirstChild .

func (*BaseNode) HasChildren

func (n *BaseNode) HasChildren() bool

HasChildren implements Node.HasChildren .

func (*BaseNode) InsertAfter

func (n *BaseNode) InsertAfter(self, v1, insertee Node)

InsertAfter implements Node.InsertAfter .

func (*BaseNode) InsertBefore

func (n *BaseNode) InsertBefore(self, v1, 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) 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(self, v Node)

RemoveChild implements Node.RemoveChild .

func (*BaseNode) RemoveChildren

func (n *BaseNode) RemoveChildren(self Node)

RemoveChildren implements Node.RemoveChildren .

func (*BaseNode) ReplaceChild

func (n *BaseNode) ReplaceChild(self, v1, insertee Node)

ReplaceChild implements Node.ReplaceChild .

func (*BaseNode) SetAttribute

func (n *BaseNode) SetAttribute(name []byte, value interface{})

SetAttribute implements Node.SetAttribute.

func (*BaseNode) SetAttributeString

func (n *BaseNode) SetAttributeString(name string, value interface{})

SetAttributeString implements Node.SetAttributeString

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) SetPreviousSibling

func (n *BaseNode) SetPreviousSibling(v Node)

SetPreviousSibling implements Node.SetPreviousSibling .

func (*BaseNode) SortChildren

func (n *BaseNode) SortChildren(comparator func(n1, n2 Node) int)

SortChildren implements Node.SortChildren

func (*BaseNode) Text

func (n *BaseNode) Text(source []byte) []byte

Text implements Node.Text .

type Blockquote

A Blockquote struct represents an blockquote block of Markdown text.

type Blockquote struct {
    BaseBlock
}

func NewBlockquote

func NewBlockquote() *Blockquote

NewBlockquote returns a new Blockquote node.

func (*Blockquote) Dump

func (n *Blockquote) Dump(source []byte, level int)

Dump implements Node.Dump .

func (*Blockquote) Kind

func (n *Blockquote) Kind() NodeKind

Kind implements Node.Kind.

type CodeBlock

A CodeBlock interface represents an indented code block of Markdown text.

type CodeBlock struct {
    BaseBlock
}

func NewCodeBlock

func NewCodeBlock() *CodeBlock

NewCodeBlock returns a new CodeBlock node.

func (*CodeBlock) Dump

func (n *CodeBlock) Dump(source []byte, level int)

Dump implements Node.Dump .

func (*CodeBlock) IsRaw

func (n *CodeBlock) IsRaw() bool

IsRaw implements Node.IsRaw.

func (*CodeBlock) Kind

func (n *CodeBlock) Kind() NodeKind

Kind implements Node.Kind.

type CodeSpan

A CodeSpan struct represents a code span of Markdown text.

type CodeSpan struct {
    BaseInline
}

func NewCodeSpan

func NewCodeSpan() *CodeSpan

NewCodeSpan returns a new CodeSpan node.

func (*CodeSpan) Dump

func (n *CodeSpan) Dump(source []byte, level int)

Dump implements Node.Dump

func (*CodeSpan) Inline

func (n *CodeSpan) Inline()

Inline implements Inline.Inline .

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.

type Document

A Document struct is a root node of Markdown text.

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

func NewDocument

func NewDocument() *Document

NewDocument returns a new Document node.

func (*Document) AddMeta

func (n *Document) AddMeta(key string, value interface{})

AddMeta adds given metadata to this document.

func (*Document) Dump

func (n *Document) Dump(source []byte, level int)

Dump implements Node.Dump .

func (*Document) Kind

func (n *Document) Kind() NodeKind

Kind implements Node.Kind.

func (*Document) Meta

func (n *Document) Meta() map[string]interface{}

Meta returns metadata of this document.

func (*Document) OwnerDocument

func (n *Document) OwnerDocument() *Document

OwnerDocument implements Node.OwnerDocument

func (*Document) SetMeta

func (n *Document) SetMeta(meta map[string]interface{})

SetMeta sets given metadata to this document.

func (*Document) Type

func (n *Document) Type() NodeType

Type implements Node.Type .

type Emphasis

An Emphasis struct represents an emphasis of Markdown text.

type Emphasis struct {
    BaseInline

    // Level is a level of the emphasis.
    Level int
}

func NewEmphasis

func NewEmphasis(level int) *Emphasis

NewEmphasis returns a new Emphasis node with the given level.

func (*Emphasis) Dump

func (n *Emphasis) Dump(source []byte, level int)

Dump implements Node.Dump.

func (*Emphasis) Kind

func (n *Emphasis) Kind() NodeKind

Kind implements Node.Kind.

type FencedCodeBlock

A FencedCodeBlock struct represents a fenced code block of Markdown text.

type FencedCodeBlock struct {
    BaseBlock
    // Info returns a info text of this fenced code block.
    Info *Text
    // contains filtered or unexported fields
}

func NewFencedCodeBlock

func NewFencedCodeBlock(info *Text) *FencedCodeBlock

NewFencedCodeBlock return a new FencedCodeBlock node.

func (*FencedCodeBlock) Dump

func (n *FencedCodeBlock) Dump(source []byte, level int)

Dump implements Node.Dump .

func (*FencedCodeBlock) IsRaw

func (n *FencedCodeBlock) IsRaw() bool

IsRaw implements Node.IsRaw.

func (*FencedCodeBlock) Kind

func (n *FencedCodeBlock) Kind() NodeKind

Kind implements Node.Kind.

func (*FencedCodeBlock) Language

func (n *FencedCodeBlock) Language(source []byte) []byte

Language returns an language in an info string. Language returns nil if this node does not have an info string.

type HTMLBlock

An HTMLBlock struct represents an html block of Markdown text.

type HTMLBlock struct {
    BaseBlock

    // Type is a type of this html block.
    HTMLBlockType HTMLBlockType

    // ClosureLine is a line that closes this html block.
    ClosureLine textm.Segment
}

func NewHTMLBlock

func NewHTMLBlock(typ HTMLBlockType) *HTMLBlock

NewHTMLBlock returns a new HTMLBlock node.

func (*HTMLBlock) Dump

func (n *HTMLBlock) Dump(source []byte, level int)

Dump implements Node.Dump.

func (*HTMLBlock) HasClosure

func (n *HTMLBlock) HasClosure() bool

HasClosure returns true if this html block has a closure line, otherwise false.

func (*HTMLBlock) IsRaw

func (n *HTMLBlock) IsRaw() bool

IsRaw implements Node.IsRaw.

func (*HTMLBlock) Kind

func (n *HTMLBlock) Kind() NodeKind

Kind implements Node.Kind.

type HTMLBlockType

HTMLBlockType represents kinds of an html blocks. See https://spec.commonmark.org/0.30/#html-blocks

type HTMLBlockType int
const (
    // HTMLBlockType1 represents type 1 html blocks
    HTMLBlockType1 HTMLBlockType = iota + 1
    // HTMLBlockType2 represents type 2 html blocks
    HTMLBlockType2
    // HTMLBlockType3 represents type 3 html blocks
    HTMLBlockType3
    // HTMLBlockType4 represents type 4 html blocks
    HTMLBlockType4
    // HTMLBlockType5 represents type 5 html blocks
    HTMLBlockType5
    // HTMLBlockType6 represents type 6 html blocks
    HTMLBlockType6
    // HTMLBlockType7 represents type 7 html blocks
    HTMLBlockType7
)

type Heading

A Heading struct represents headings like SetextHeading and ATXHeading.

type Heading struct {
    BaseBlock
    // Level returns a level of this heading.
    // This value is between 1 and 6.
    Level int
}

func NewHeading

func NewHeading(level int) *Heading

NewHeading returns a new Heading node.

func (*Heading) Dump

func (n *Heading) Dump(source []byte, level int)

Dump implements Node.Dump .

func (*Heading) Kind

func (n *Heading) Kind() NodeKind

Kind implements Node.Kind.

type Image

An Image struct represents an image of the Markdown text.

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

func NewImage

func NewImage(link *Link) *Image

NewImage returns a new Image node.

func (*Image) Dump

func (n *Image) Dump(source []byte, level int)

Dump implements Node.Dump.

func (*Image) Inline

func (n *Image) Inline()

Inline implements Inline.Inline.

func (*Image) Kind

func (n *Image) Kind() NodeKind

Kind implements Node.Kind.

A Link struct represents a link of the Markdown text.

type Link struct {
    // contains filtered or unexported fields
}
func NewLink() *Link

NewLink returns a new Link node.

func (*Link) Dump

func (n *Link) Dump(source []byte, level int)

Dump implements Node.Dump.

func (*Link) Inline

func (n *Link) Inline()

Inline implements Inline.Inline.

func (*Link) Kind

func (n *Link) Kind() NodeKind

Kind implements Node.Kind.

type List

A List struct represents a list of Markdown text.

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
}

func NewList

func NewList(marker byte) *List

NewList returns a new List node.

func (*List) CanContinue

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

CanContinue returns true if this list can continue with the given mark and a list type, otherwise false.

func (*List) Dump

func (l *List) Dump(source []byte, level int)

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.

type ListItem

A ListItem struct represents a list item of Markdown text.

type ListItem struct {
    BaseBlock

    // Offset is an offset position of this item.
    Offset int
}

func NewListItem

func NewListItem(offset int) *ListItem

NewListItem returns a new ListItem node.

func (*ListItem) Dump

func (n *ListItem) Dump(source []byte, level int)

Dump implements Node.Dump.

func (*ListItem) Kind

func (n *ListItem) Kind() NodeKind

Kind implements Node.Kind.

type Node

A Node interface defines basic AST node functionalities.

type Node interface {
    // Type returns a type of this node.
    Type() NodeType

    // Kind returns a kind of this node.
    Kind() NodeKind

    // 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

    // 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(self, 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(self, child Node)

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

    // SortChildren sorts childrens by comparator.
    SortChildren(comparator func(n1, n2 Node) int)

    // ReplaceChild replace a node v1 with a node insertee.
    // If v1 is not children of this node, ReplaceChild append a insetee to the
    // tail of the children.
    ReplaceChild(self, v1, insertee Node)

    // InsertBefore inserts a node insertee before a node v1.
    // If v1 is not children of this node, InsertBefore append a insetee to the
    // tail of the children.
    InsertBefore(self, v1, insertee Node)

    // InsertAfterinserts a node insertee after a node v1.
    // If v1 is not children of this node, InsertBefore append a insetee to the
    // tail of the children.
    InsertAfter(self, v1, 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 tree structure to stdout.
    // This function completely aimed for debugging.
    // level is a indent level. Implementer should indent informations with
    // 2 * level spaces.
    Dump(source []byte, level int)

    // Text returns text values of this node.
    Text(source []byte) []byte

    // HasBlankPreviousLines returns true if the row before this node is blank,
    // otherwise false.
    // This method is valid only for block nodes.
    HasBlankPreviousLines() bool

    // SetBlankPreviousLines sets whether the row before this node is blank.
    // This method is valid only for block nodes.
    SetBlankPreviousLines(v bool)

    // Lines returns text segments that hold positions in a source.
    // This method is valid only for block nodes.
    Lines() *textm.Segments

    // SetLines sets text segments that hold positions in a source.
    // This method is valid only for block nodes.
    SetLines(*textm.Segments)

    // IsRaw returns true if contents should be rendered as 'raw' contents.
    IsRaw() bool

    // SetAttribute sets the given value to the attributes.
    SetAttribute(name []byte, value interface{})

    // SetAttributeString sets the given value to the attributes.
    SetAttributeString(name string, value interface{})

    // Attribute returns a (attribute value, true) if an attribute
    // associated with the given name is found, otherwise
    // (nil, false)
    Attribute(name []byte) (interface{}, bool)

    // AttributeString returns a (attribute value, true) if an attribute
    // associated with the given name is found, otherwise
    // (nil, false)
    AttributeString(name string) (interface{}, 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()
}

type NodeKind

NodeKind indicates more specific type than NodeType.

type NodeKind int

func NewNodeKind

func NewNodeKind(name string) NodeKind

NewNodeKind returns a new Kind value.

func (NodeKind) String

func (k NodeKind) String() string

type NodeType

A NodeType indicates what type a node belongs to.

type NodeType int
const (
    // TypeBlock indicates that a node is kind of block nodes.
    TypeBlock NodeType = iota + 1
    // TypeInline indicates that a node is kind of inline nodes.
    TypeInline
    // TypeDocument indicates that a node is kind of document nodes.
    TypeDocument
)

type Paragraph

A Paragraph struct represents a paragraph of Markdown text.

type Paragraph struct {
    BaseBlock
}

func NewParagraph

func NewParagraph() *Paragraph

NewParagraph returns a new Paragraph node.

func (*Paragraph) Dump

func (n *Paragraph) Dump(source []byte, level int)

Dump implements Node.Dump .

func (*Paragraph) Kind

func (n *Paragraph) Kind() NodeKind

Kind implements Node.Kind.

type RawHTML

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

type RawHTML struct {
    BaseInline
    Segments *textm.Segments
}

func NewRawHTML

func NewRawHTML() *RawHTML

NewRawHTML returns a new RawHTML node.

func (*RawHTML) Dump

func (n *RawHTML) Dump(source []byte, level int)

Dump implements Node.Dump.

func (*RawHTML) Inline

func (n *RawHTML) Inline()

Inline implements Inline.Inline.

func (*RawHTML) Kind

func (n *RawHTML) Kind() NodeKind

Kind implements Node.Kind.

type String

A String struct is a textual content that has a concrete value

type String struct {
    BaseInline

    Value []byte
    // contains filtered or unexported fields
}

func NewString

func NewString(v []byte) *String

NewString returns a new String node.

func (*String) Dump

func (n *String) Dump(source []byte, level int)

Dump implements Node.Dump.

func (*String) Inline

func (n *String) Inline()

Inline implements Inline.Inline.

func (*String) IsCode

func (n *String) IsCode() bool

IsCode returns true if this text should be rendered without any modifications.

func (*String) IsRaw

func (n *String) IsRaw() bool

IsRaw returns true if this text should be rendered without unescaping back slash escapes and resolving references.

func (*String) Kind

func (n *String) Kind() NodeKind

Kind implements Node.Kind.

func (*String) SetCode

func (n *String) SetCode(v bool)

SetCode sets whether this text should be rendered without any modifications.

func (*String) SetRaw

func (n *String) SetRaw(v bool)

SetRaw sets whether this text should be rendered as raw contents.

func (*String) Text

func (n *String) Text(source []byte) []byte

Text implements Node.Text.

type Text

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

type Text struct {
    BaseInline
    // Segment is a position in a source text.
    Segment textm.Segment
    // contains filtered or unexported fields
}

func NewRawTextSegment

func NewRawTextSegment(v textm.Segment) *Text

NewRawTextSegment returns a new Text node with the given source position. The new node should be rendered as raw contents.

func NewText

func NewText() *Text

NewText returns a new Text node.

func NewTextSegment

func NewTextSegment(v textm.Segment) *Text

NewTextSegment returns a new Text node with the given source position.

func (*Text) Dump

func (n *Text) Dump(source []byte, level int)

Dump implements Node.Dump.

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) Inline

func (n *Text) Inline()

Inline implements Inline.Inline.

func (*Text) IsRaw

func (n *Text) IsRaw() bool

IsRaw returns true if this text should be rendered without unescaping back slash escapes and resolving references.

func (*Text) Kind

func (n *Text) Kind() NodeKind

Kind implements Node.Kind.

func (*Text) Merge

func (n *Text) Merge(node Node, source []byte) bool

Merge merges a Node n into this node. Merge returns true if the given node has been merged, otherwise false.

func (*Text) SetHardLineBreak

func (n *Text) SetHardLineBreak(v bool)

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

func (*Text) SetRaw

func (n *Text) SetRaw(v bool)

SetRaw sets whether this text should be rendered as raw contents.

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.

func (*Text) Text

func (n *Text) Text(source []byte) []byte

Text implements Node.Text.

type TextBlock

A TextBlock struct is a node whose lines should be rendered without any containers.

type TextBlock struct {
    BaseBlock
}

func NewTextBlock

func NewTextBlock() *TextBlock

NewTextBlock returns a new TextBlock node.

func (*TextBlock) Dump

func (n *TextBlock) Dump(source []byte, level int)

Dump implements Node.Dump .

func (*TextBlock) Kind

func (n *TextBlock) Kind() NodeKind

Kind implements Node.Kind.

type ThematicBreak

A ThematicBreak struct represents a thematic break of Markdown text.

type ThematicBreak struct {
    BaseBlock
}

func NewThematicBreak

func NewThematicBreak() *ThematicBreak

NewThematicBreak returns a new ThematicBreak node.

func (*ThematicBreak) Dump

func (n *ThematicBreak) Dump(source []byte, level int)

Dump implements Node.Dump .

func (*ThematicBreak) Kind

func (n *ThematicBreak) Kind() NodeKind

Kind implements Node.Kind.

type WalkStatus

WalkStatus represents a current status of the Walk function.

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

    // WalkSkipChildren indicates that Walk wont walk on children of current
    // node.
    WalkSkipChildren

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

type Walker

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.

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