Documentation ¶
Overview ¶
Package ast defines tree representation of a parsed markdown document.
Index ¶
- func AppendChild(parent Node, child Node)
- func Print(dst io.Writer, doc Node)
- func PrintWithPrefix(w io.Writer, doc Node, prefix string)
- func RemoveFromTree(n Node)
- func ToString(doc Node) string
- func WalkFunc(n Node, f NodeVisitorFunc)
- type Aside
- type Attribute
- type BlockQuote
- type Callout
- type Caption
- type CaptionFigure
- type CellAlignFlags
- type Citation
- type CitationTypes
- type Code
- type CodeBlock
- type Container
- func (c *Container) AsContainer() *Container
- func (c *Container) AsLeaf() *Leaf
- func (c *Container) GetChildren() []Node
- func (c *Container) GetParent() Node
- func (c *Container) MarshalJSON() ([]byte, error)
- func (c *Container) SetChildren(newChildren []Node)
- func (c *Container) SetParent(newParent Node)
- type CrossReference
- type Del
- type Document
- type DocumentMatter
- type DocumentMatters
- type Emph
- type Footnotes
- type HTMLBlock
- type HTMLSpan
- type Hardbreak
- type Heading
- type HorizontalRule
- type Image
- type Index
- type Leaf
- type Link
- type List
- type ListItem
- type ListType
- type Math
- type MathBlock
- type Mention
- type Node
- type NodeVisitor
- type NodeVisitorFunc
- type NonBlockingSpace
- type Paragraph
- type Softbreak
- type StatusTag
- type Strong
- type StrongEmph
- type Subscript
- type Superscript
- type Table
- type TableBody
- type TableCell
- type TableFooter
- type TableHeader
- type TableRow
- type Text
- type WalkStatus
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendChild ¶
AppendChild appends child to children of parent It panics if either node is nil.
func Print ¶
Print is for debugging. It prints a string representation of parsed markdown doc (result of parser.Parse()) to dst.
To make output readable, it shortens text output.
func PrintWithPrefix ¶
PrintWithPrefix is like Print but allows customizing prefix used for indentation. By default it's 2 spaces. You can change it to e.g. tab by passing "\t"
func WalkFunc ¶
func WalkFunc(n Node, f NodeVisitorFunc)
WalkFunc is like Walk but accepts just a callback function
Types ¶
type Attribute ¶
An attribute can be attached to block elements. They are specified as {#id .classs key="value"} where quotes for values are mandatory, multiple key/value pairs are separated by whitespace.
type BlockQuote ¶
type BlockQuote struct {
Container
}
BlockQuote represents markdown block quote node
func (*BlockQuote) MarshalJSON ¶
func (c *BlockQuote) MarshalJSON() ([]byte, error)
type Callout ¶
Callout is a node that can exist both in text (where it is an actual node) and in a code block.
type CaptionFigure ¶
CaptionFigure is a node (blockquote or codeblock) that has a caption
type CellAlignFlags ¶
type CellAlignFlags int
CellAlignFlags holds a type of alignment in a table cell.
const ( TableAlignmentLeft CellAlignFlags = 1 << iota TableAlignmentRight TableAlignmentCenter = (TableAlignmentLeft | TableAlignmentRight) )
These are the possible flag values for the table cell renderer. Only a single one of these values will be used; they are not ORed together. These are mostly of interest if you are writing a new output format.
func (CellAlignFlags) String ¶
func (a CellAlignFlags) String() string
type Citation ¶
type Citation struct { Leaf Destination [][]byte // Destination is where the citation points to. Multiple ones are allowed. Type []CitationTypes // 1:1 mapping of destination and citation type Suffix [][]byte // Potential citation suffix, i.e. [@!RFC1035, p. 144] }
Citation is a citation node.
type CitationTypes ¶
type CitationTypes int
CitationTypes holds the type of a citation, informative, normative or suppressed
const ( CitationTypeNone CitationTypes = iota CitationTypeSuppressed CitationTypeInformative CitationTypeNormative )
type CodeBlock ¶
type CodeBlock struct { Leaf IsFenced bool // Specifies whether it's a fenced code block or an indented one Info []byte // This holds the info string FenceChar byte FenceLength int FenceOffset int }
CodeBlock represents markdown code block node
func (*CodeBlock) MarshalJSON ¶
type Container ¶
type Container struct { Parent Node `json:"-"` Children []Node Literal []byte // Text contents of the leaf nodes Content []byte // Markdown content of the block nodes *Attribute // Block level attribute }
Container is a type of node that can contain children
func (*Container) AsContainer ¶
AsContainer returns itself as *Container
func (*Container) GetChildren ¶
GetChildren returns children nodes
func (*Container) MarshalJSON ¶
func (*Container) SetChildren ¶
SetChildren sets children node
type CrossReference ¶
type CrossReference struct { Container Destination []byte // Destination is where the reference points to }
CrossReference is a reference node.
type Document ¶
type Document struct {
Container
}
Document represents markdown document node, a root of ast
func (*Document) MarshalJSON ¶
type DocumentMatter ¶
type DocumentMatter struct { Container Matter DocumentMatters }
DocumentMatter represents markdown node that signals a document division: frontmatter, mainmatter or backmatter.
type DocumentMatters ¶
type DocumentMatters int
DocumentMatters holds the type of a {front,main,back}matter in the document
const ( DocumentMatterNone DocumentMatters = iota DocumentMatterFront DocumentMatterMain DocumentMatterBack )
These are all possible Document divisions.
type Emph ¶
type Emph struct {
Leaf
}
Emph represents markdown emphasis node
func (*Emph) MarshalJSON ¶
type Footnotes ¶
type Footnotes struct {
Container
}
Footnotes is a node that contains all footnotes
type Heading ¶
type Heading struct { Container Level int // This holds the heading level number HeadingID string // This might hold heading ID, if present IsTitleblock bool // Specifies whether it's a title block IsSpecial bool // We are a special heading (starts with .#) }
Heading represents markdown heading node
func (*Heading) MarshalJSON ¶
type HorizontalRule ¶
type HorizontalRule struct {
Leaf
}
HorizontalRule represents markdown horizontal rule node
type Image ¶
type Image struct { Container Destination []byte // Destination is what goes into a href Title []byte // Title is the tooltip thing that goes in a title attribute }
Image represents markdown image node
type Leaf ¶
type Leaf struct { Parent Node `json:"-"` Literal []byte // Text contents of the leaf nodes Content []byte // Markdown content of the block nodes *Attribute // Block level attribute }
Leaf is a type of node that cannot have children
func (*Leaf) GetChildren ¶
GetChildren returns nil because Leaf cannot have children
func (*Leaf) MarshalJSON ¶
func (*Leaf) SetChildren ¶
SetChildren will panic becuase Leaf cannot have children
type Link ¶
type Link struct { Container Destination []byte // Destination is what goes into a href Title []byte // Title is the tooltip thing that goes in a title attribute NoteID int // NoteID contains a serial number of a footnote, zero if it's not a footnote Footnote Node // If it's a footnote, this is a direct link to the footnote Node. Otherwise nil. DeferredID []byte // If a deferred link this holds the original ID. }
Link represents markdown link node
func (*Link) MarshalJSON ¶
type List ¶
type List struct { Container ListFlags ListType Tight bool // Skip <p>s around list item data if true BulletChar byte // '*', '+' or '-' in bullet lists Delimiter byte // '.' or ')' after the number in ordered lists Start int // for ordered lists this indicates the starting number if > 0 RefLink []byte // If not nil, turns this list item into a footnote item and triggers different rendering IsFootnotesList bool // This is a list of footnotes }
List represents markdown list node
type ListItem ¶
type ListItem struct { Container ListFlags ListType Tight bool // Skip <p>s around list item data if true BulletChar byte // '*', '+' or '-' in bullet lists Delimiter byte // '.' or ')' after the number in ordered lists RefLink []byte // If not nil, turns this list item into a footnote item and triggers different rendering IsFootnotesList bool // This is a list of footnotes }
ListItem represents markdown list item node
type ListType ¶
type ListType int
ListType contains bitwise or'ed flags for list and list item objects.
const ( ListTypeOrdered ListType = 1 << iota ListTypeDefinition ListTypeTerm ListItemContainsBlock ListItemBeginningOfList // TODO: figure out if this is of any use now ListItemEndOfList )
These are the possible flag values for the ListItem renderer. Multiple flag values may be ORed together. These are mostly of interest if you are writing a new output format.
type MathBlock ¶
type MathBlock struct {
Container
}
MathBlock represents markdown MathAjax block node
type Node ¶
type Node interface { AsContainer() *Container AsLeaf() *Leaf GetParent() Node SetParent(newParent Node) GetChildren() []Node SetChildren(newChildren []Node) }
Node defines an ast node
func GetFirstChild ¶
GetFirstChild returns first child of node n It's implemented as stand-alone function to keep Node interface small
func GetLastChild ¶
GetLastChild returns last child of node n It's implemented as stand-alone function to keep Node interface small
func GetNextNode ¶
GetNextNode returns next sibling of node n (node after n) We can't make it part of Container or Leaf because we loose Node identity
func GetPrevNode ¶
GetPrevNode returns previous sibling of node n (node before n) We can't make it part of Container or Leaf because we loose Node identity
type NodeVisitor ¶
type NodeVisitor interface {
Visit(node Node, entering bool) WalkStatus
}
NodeVisitor is a callback to be called when traversing the syntax tree. Called twice for every node: once with entering=true when the branch is first visited, then with entering=false after all the children are done.
type NodeVisitorFunc ¶
type NodeVisitorFunc func(node Node, entering bool) WalkStatus
NodeVisitorFunc casts a function to match NodeVisitor interface
func (NodeVisitorFunc) Visit ¶
func (f NodeVisitorFunc) Visit(node Node, entering bool) WalkStatus
Visit calls visitor function
type NonBlockingSpace ¶
type NonBlockingSpace struct {
Leaf
}
NonBlockingSpace represents markdown non-blocking space node
type Paragraph ¶
type Paragraph struct {
Container
}
Paragraph represents markdown paragraph node
func (*Paragraph) MarshalJSON ¶
type Softbreak ¶
type Softbreak struct {
Leaf
}
Softbreak represents markdown softbreak node Note: not used currently
type Strong ¶
type Strong struct {
Leaf
}
Strong represents markdown strong node
func (*Strong) MarshalJSON ¶
type StrongEmph ¶
type StrongEmph struct {
Leaf
}
StrongEmph represents markdown strong emphasis node
func (*StrongEmph) MarshalJSON ¶
func (c *StrongEmph) MarshalJSON() ([]byte, error)
type TableCell ¶
type TableCell struct { Container IsHeader bool // This tells if it's under the header row Align CellAlignFlags // This holds the value for align attribute }
TableCell represents markdown table cell node
type TableHeader ¶
type TableHeader struct {
Container
}
TableHeader represents markdown table head node
type WalkStatus ¶
type WalkStatus int
WalkStatus allows NodeVisitor to have some control over the tree traversal. It is returned from NodeVisitor and different values allow Node.Walk to decide which node to go to next.
const ( // GoToNext is the default traversal of every node. GoToNext WalkStatus = iota // SkipChildren tells walker to skip all children of current node. SkipChildren // Terminate tells walker to terminate the traversal. Terminate )