From 93f691a086d7142c02dba405b608ffb0d14e77fc Mon Sep 17 00:00:00 2001 From: Dmitry Sedykh Date: Wed, 25 Dec 2019 23:07:59 +0300 Subject: [PATCH] add link & image atributes parser --- ast/inline.go | 4 ++++ parser/link.go | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/ast/inline.go b/ast/inline.go index da0f720..0ac06d1 100644 --- a/ast/inline.go +++ b/ast/inline.go @@ -438,6 +438,10 @@ func NewImage(link *Link) *Image { c.AppendChild(c, n) n = next } + // copy attributes + for _, attr := range link.Attributes() { + c.SetAttribute(attr.Name, attr.Value) + } return c } diff --git a/parser/link.go b/parser/link.go index 6326585..9118397 100644 --- a/parser/link.go +++ b/parser/link.go @@ -99,7 +99,20 @@ func removeLinkLabelState(pc Context, d *linkLabelState) { d.Last = nil } +// A AttributeConfig struct is a data structure that holds configuration of the renderers attributes. +type AttributeConfig struct { + Attribute bool +} + +// SetOption implements SetOptioner. +func (a *AttributeConfig) SetOption(name OptionName, value interface{}) { + if name == optAttribute { + a.Attribute = true + } +} + type linkParser struct { + AttributeConfig } var defaultLinkParser = &linkParser{} @@ -182,6 +195,14 @@ func (s *linkParser) Parse(parent ast.Node, block text.Reader, pc Context) ast.N link.Title = ref.Title() link.Destination = ref.Destination() } + // parse attributes + if s.Attribute { + if attrs, ok := ParseAttributes(block); ok { + for _, attr := range attrs { + link.SetAttribute(attr.Name, attr.Value) + } + } + } if last.IsImage { last.Parent().RemoveChild(last.Parent(), last) return ast.NewImage(link)