Add AttributeString method

This commit is contained in:
yuin 2019-05-04 22:29:53 +09:00
parent bdde5e8472
commit 3bf70b9428

View file

@ -5,6 +5,7 @@ import (
"bytes" "bytes"
"fmt" "fmt"
textm "github.com/yuin/goldmark/text" textm "github.com/yuin/goldmark/text"
"github.com/yuin/goldmark/util"
"strings" "strings"
) )
@ -148,6 +149,11 @@ type Node interface {
// (nil, false) // (nil, false)
Attribute(name []byte) ([]byte, bool) Attribute(name []byte) ([]byte, bool)
// AttributeString returns a (attribute value, true) if an attribute
// associated with the given name is found, otherwise
// (nil, false)
AttributeString(name string) ([]byte, bool)
// Attributes returns a list of attributes. // Attributes returns a list of attributes.
// This may be a nil if there are no attributes. // This may be a nil if there are no attributes.
Attributes() []Attribute Attributes() []Attribute
@ -355,6 +361,11 @@ func (n *BaseNode) Attribute(name []byte) ([]byte, bool) {
return nil, false return nil, false
} }
// AttributeString implements Node.AttributeString.
func (n *BaseNode) AttributeString(s string) ([]byte, bool) {
return n.Attribute(util.StringToReadOnlyBytes(s))
}
// Attributes implements Node.Attributes // Attributes implements Node.Attributes
func (n *BaseNode) Attributes() []Attribute { func (n *BaseNode) Attributes() []Attribute {
return n.attributes return n.attributes