mirror of
https://github.com/yuin/goldmark
synced 2025-03-04 23:04:52 +00:00
add link & image atributes parser
This commit is contained in:
parent
afb6db3f1a
commit
93f691a086
2 changed files with 25 additions and 0 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue