Source File
ast.go
Belonging Package
github.com/yuin/goldmark/ast
package ast
import (
textm
)
Type() NodeType
Kind() NodeKind
NextSibling() Node
PreviousSibling() Node
Parent() Node
SetParent(Node)
SetPreviousSibling(Node)
SetNextSibling(Node)
HasChildren() bool
ChildCount() int
FirstChild() Node
LastChild() Node
AppendChild(self, child Node)
RemoveChild(self, child Node)
RemoveChildren(self Node)
ReplaceChild(self, v1, insertee Node)
InsertBefore(self, v1, insertee Node)
InsertAfter(self, v1, insertee Node)
OwnerDocument() *Document
HasBlankPreviousLines() bool
SetBlankPreviousLines(v bool)
IsRaw() bool
SetAttribute(name []byte, value interface{})
SetAttributeString(name string, value interface{})
Attributes() []Attribute
RemoveAttributes()
}
type BaseNode struct {
firstChild Node
lastChild Node
parent Node
next Node
prev Node
childCount int
attributes []Attribute
}
func ( Node) {
if := .Parent(); != nil {
.RemoveChild(, )
}
}
func ( *BaseNode) () bool {
return .firstChild != nil
}
func ( *BaseNode) (, Node) {
if .Parent() != {
return
}
.childCount--
:= .PreviousSibling()
:= .NextSibling()
if != nil {
.SetNextSibling()
} else {
.firstChild =
}
if != nil {
.SetPreviousSibling()
} else {
.lastChild =
}
.SetParent(nil)
.SetPreviousSibling(nil)
.SetNextSibling(nil)
}
func ( *BaseNode) ( Node) {
for := .firstChild; != nil; {
.SetParent(nil)
.SetPreviousSibling(nil)
:= .NextSibling()
.SetNextSibling(nil)
=
}
.firstChild = nil
.lastChild = nil
.childCount = 0
}
func ( *BaseNode) ( func(, Node) int) {
var Node
:= .firstChild
for != nil {
:= .NextSibling()
if == nil || (, ) >= 0 {
.SetNextSibling()
if != nil {
.SetPreviousSibling()
}
=
.SetPreviousSibling(nil)
} else {
:=
for .NextSibling() != nil && (.NextSibling(), ) < 0 {
= .NextSibling()
}
.SetNextSibling(.NextSibling())
.SetPreviousSibling()
if .NextSibling() != nil {
.NextSibling().SetPreviousSibling()
}
.SetNextSibling()
}
=
}
.firstChild =
for := .firstChild; != nil; = .NextSibling() {
.lastChild =
}
}
func ( *BaseNode) () Node {
return .firstChild
}
func ( *BaseNode) () int {
return .childCount
}
func ( *BaseNode) (, Node) {
ensureIsolated()
if .firstChild == nil {
.firstChild =
.SetNextSibling(nil)
.SetPreviousSibling(nil)
} else {
:= .lastChild
.SetNextSibling()
.SetPreviousSibling()
}
.SetParent()
.lastChild =
.childCount++
}
func ( *BaseNode) (, , Node) {
.InsertBefore(, , )
.RemoveChild(, )
}
func ( *BaseNode) (, , Node) {
.InsertBefore(, .NextSibling(), )
}
func ( *BaseNode) (, , Node) {
.childCount++
if == nil {
.AppendChild(, )
return
}
ensureIsolated()
if .Parent() == {
:=
:= .PreviousSibling()
if != nil {
.SetNextSibling()
.SetPreviousSibling()
} else {
.firstChild =
.SetPreviousSibling(nil)
}
.SetNextSibling()
.SetPreviousSibling()
.SetParent()
}
}
func ( *BaseNode) ( []byte, interface{}) {
if .attributes == nil {
.attributes = make([]Attribute, 0, 10)
} else {
for , := range .attributes {
if bytes.Equal(.Name, ) {
.attributes[].Name =
.attributes[].Value =
return
}
}
}
.attributes = append(.attributes, Attribute{, })
}
func ( *BaseNode) ( string, interface{}) {
.SetAttribute(util.StringToReadOnlyBytes(), )
}
func ( *BaseNode) () []Attribute {
return .attributes
}
func ( *BaseNode) () {
.attributes = nil
}
func ( Node, []byte, int, map[string]string, func(int)) {
:= .Kind().String()
:= strings.Repeat(" ", )
fmt.Printf("%s%s {\n", , )
:= strings.Repeat(" ", +1)
if .Type() == TypeBlock {
fmt.Printf("%sRawText: \"", )
for := 0; < .Lines().Len(); ++ {
:= .Lines().At()
fmt.Printf("%s", .Value())
}
fmt.Printf("\"\n")
fmt.Printf("%sHasBlankPreviousLines: %v\n", , .HasBlankPreviousLines())
}
for , := range {
fmt.Printf("%s%s: %s\n", , , )
}
if != nil {
( + 1)
}
for := .FirstChild(); != nil; = .NextSibling() {
.Dump(, +1)
}
fmt.Printf("%s}\n", )
}
type WalkStatus int
WalkStop WalkStatus = iota + 1
type Walker func(n Node, entering bool) (WalkStatus, error)
func ( Node, Walker) error {
, := walkHelper(, )
return
}
func ( Node, Walker) (WalkStatus, error) {
, := (, true)
if != nil || == WalkStop {
return ,
}
if != WalkSkipChildren {
for := .FirstChild(); != nil; = .NextSibling() {
if , := (, ); != nil || == WalkStop {
return WalkStop,
}
}
}
, = (, false)
if != nil || == WalkStop {
return WalkStop,
}
return WalkContinue, nil
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |