Skip to content

Commit

Permalink
Merge pull request #308 from Seanld/defs-style-support
Browse files Browse the repository at this point in the history
Handle SVG files with <style> nested under <defs>
  • Loading branch information
tdewolff committed Jul 14, 2024
2 parents 2c90ad9 + 4558e1f commit a65f42e
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion svg.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,11 @@ func (svg *svgParser) parseTag(l *xml.Lexer) *svgTag {
} else if tt == xml.StartTagToken {
var attrNames []string
var attrs map[string]string
name := string(data[1:])
tt, attrNames, attrs = svg.parseAttributes(l)
tag := &svgTag{
parent: parent,
name: string(data[1:]),
name: name,
attrNames: attrNames,
attrs: attrs,
}
Expand All @@ -408,6 +409,19 @@ func (svg *svgParser) parseTag(l *xml.Lexer) *svgTag {
} else {
parent = tag
}

// Handle <style> being nested in <defs>. Adobe Illustrator
// does this, for example.
if name == "style" {
tt, data = l.Next()
if tt == xml.TextToken {
svg.parseStyle(data)
tt, data = l.Next()
} else {
svg.err = parse.NewErrorLexer(svg.z, "Bad style tag")
}
break
}
} else if tt == xml.EndTagToken {
if parent == nil {
break // when starting on an end tag
Expand Down

0 comments on commit a65f42e

Please sign in to comment.