summaryrefslogtreecommitdiff
path: root/vendor/github.com/yuin/goldmark/ast/ast.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/yuin/goldmark/ast/ast.go')
-rw-r--r--vendor/github.com/yuin/goldmark/ast/ast.go58
1 files changed, 48 insertions, 10 deletions
diff --git a/vendor/github.com/yuin/goldmark/ast/ast.go b/vendor/github.com/yuin/goldmark/ast/ast.go
index 36ba606..e4bd205 100644
--- a/vendor/github.com/yuin/goldmark/ast/ast.go
+++ b/vendor/github.com/yuin/goldmark/ast/ast.go
@@ -42,7 +42,7 @@ func NewNodeKind(name string) NodeKind {
// An Attribute is an attribute of the Node.
type Attribute struct {
Name []byte
- Value interface{}
+ Value any
}
// A Node interface defines basic AST node functionalities.
@@ -53,6 +53,15 @@ 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
@@ -152,20 +161,20 @@ type Node interface {
IsRaw() bool
// SetAttribute sets the given value to the attributes.
- SetAttribute(name []byte, value interface{})
+ SetAttribute(name []byte, value any)
// SetAttributeString sets the given value to the attributes.
- SetAttributeString(name string, value interface{})
+ SetAttributeString(name string, value any)
// Attribute returns a (attribute value, true) if an attribute
// associated with the given name is found, otherwise
// (nil, false)
- Attribute(name []byte) (interface{}, bool)
+ Attribute(name []byte) (any, 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)
+ AttributeString(name string) (any, bool)
// Attributes returns a list of attributes.
// This may be a nil if there are no attributes.
@@ -175,6 +184,23 @@ type Node interface {
RemoveAttributes()
}
+type pos struct {
+ has bool
+ value int
+}
+
+func (p *pos) Pos() int {
+ if p.has {
+ return p.value
+ }
+ return -1
+}
+
+func (p *pos) SetPos(v int) {
+ p.has = true
+ p.value = v
+}
+
// A BaseNode struct implements the Node interface partialliy.
type BaseNode struct {
firstChild Node
@@ -184,6 +210,7 @@ type BaseNode struct {
prev Node
childCount int
attributes []Attribute
+ pos pos
}
func ensureIsolated(v Node) {
@@ -192,6 +219,16 @@ func ensureIsolated(v Node) {
}
}
+// Pos implements Node.Pos .
+func (n *BaseNode) Pos() int {
+ return n.pos.Pos()
+}
+
+// SetPos implements Node.SetPos .
+func (n *BaseNode) SetPos(v int) {
+ n.pos.SetPos(v)
+}
+
// HasChildren implements Node.HasChildren .
func (n *BaseNode) HasChildren() bool {
return n.firstChild != nil
@@ -397,7 +434,7 @@ func (n *BaseNode) Text(source []byte) []byte {
}
// SetAttribute implements Node.SetAttribute.
-func (n *BaseNode) SetAttribute(name []byte, value interface{}) {
+func (n *BaseNode) SetAttribute(name []byte, value any) {
if n.attributes == nil {
n.attributes = make([]Attribute, 0, 10)
} else {
@@ -413,12 +450,12 @@ func (n *BaseNode) SetAttribute(name []byte, value interface{}) {
}
// SetAttributeString implements Node.SetAttributeString.
-func (n *BaseNode) SetAttributeString(name string, value interface{}) {
+func (n *BaseNode) SetAttributeString(name string, value any) {
n.SetAttribute(util.StringToReadOnlyBytes(name), value)
}
// Attribute implements Node.Attribute.
-func (n *BaseNode) Attribute(name []byte) (interface{}, bool) {
+func (n *BaseNode) Attribute(name []byte) (any, bool) {
if n.attributes == nil {
return nil, false
}
@@ -431,7 +468,7 @@ func (n *BaseNode) Attribute(name []byte) (interface{}, bool) {
}
// AttributeString implements Node.AttributeString.
-func (n *BaseNode) AttributeString(s string) (interface{}, bool) {
+func (n *BaseNode) AttributeString(s string) (any, bool) {
return n.Attribute(util.StringToReadOnlyBytes(s))
}
@@ -453,9 +490,10 @@ func DumpHelper(v Node, source []byte, level int, kv map[string]string, cb func(
indent := strings.Repeat(" ", level)
fmt.Printf("%s%s {\n", indent, name)
indent2 := strings.Repeat(" ", level+1)
+ fmt.Printf("%sPos: %d\n", indent2, v.Pos())
if v.Type() == TypeBlock {
fmt.Printf("%sRawText: \"", indent2)
- for i := 0; i < v.Lines().Len(); i++ {
+ for i := range v.Lines().Len() {
line := v.Lines().At(i)
fmt.Printf("%s", line.Value(source))
}