From 3bf70b9428fa7ef5d873990963dca18421438ce0 Mon Sep 17 00:00:00 2001 From: yuin Date: Sat, 4 May 2019 22:29:53 +0900 Subject: [PATCH] Add AttributeString method --- ast/ast.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ast/ast.go b/ast/ast.go index 3d9097a..5e90cbb 100644 --- a/ast/ast.go +++ b/ast/ast.go @@ -5,6 +5,7 @@ import ( "bytes" "fmt" textm "github.com/yuin/goldmark/text" + "github.com/yuin/goldmark/util" "strings" ) @@ -148,6 +149,11 @@ type Node interface { // (nil, false) 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. // This may be a nil if there are no attributes. Attributes() []Attribute @@ -355,6 +361,11 @@ func (n *BaseNode) Attribute(name []byte) ([]byte, bool) { 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 func (n *BaseNode) Attributes() []Attribute { return n.attributes