Skip to content

Commit

Permalink
feat: add initial style support
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed May 7, 2024
1 parent d8ba7d4 commit 4b0b1c4
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 1 deletion.
37 changes: 37 additions & 0 deletions elements.gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -6574,6 +6574,43 @@ func (e *RectElement) MarshalXML(encoder *xml.Encoder, _ xml.StartElement) error
return encodeElement(encoder, "rect", e.attrs, e.children)
}

// A StyleElement is a style element.
type StyleElement struct {
attrs map[string]AttrValue
children []Element
}

// Style returns a new StyleElement.
func Style(children ...Element) *StyleElement {
return &StyleElement{
attrs: map[string]AttrValue{},
children: children,
}
}

// AppendChildren appends the given children.
func (e *StyleElement) AppendChildren(children ...Element) *StyleElement {
e.children = append(e.children, children...)
return e
}

// Children sets the children.
func (e *StyleElement) Children(children ...Element) *StyleElement {
e.children = children
return e
}

// Type sets the type attribute.
func (e *StyleElement) Type(_type String) *StyleElement {
e.attrs["type"] = _type
return e
}

// MarshallXML implements encoding/xml.Marshaller.MarshalXML.
func (e *StyleElement) MarshalXML(encoder *xml.Encoder, _ xml.StartElement) error {
return encodeElement(encoder, "style", e.attrs, e.children)
}

// A SwitchElement is a switch element.
type SwitchElement struct {
attrs map[string]AttrValue
Expand Down
7 changes: 7 additions & 0 deletions elements.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,13 @@ elements:
- name: ry
exportedGoName: RY

- name: style
container: true
attributes:
- name: type
goName: _type
exportedGoName: Type

- name: switch
container: true
attributeGroups:
Expand Down
3 changes: 2 additions & 1 deletion svg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"path/filepath"
"slices"
"strings"
"testing"

"github.com/alecthomas/assert/v2"
Expand Down Expand Up @@ -347,7 +348,7 @@ func normalizedXMLTokens(data []byte) ([]any, error) {
var normalizedToken any
switch token := token.(type) {
case xml.CharData:
normalizedToken = string(token)
normalizedToken = string(bytes.TrimSpace(token))
case xml.StartElement:
slices.SortFunc(token.Attr, func(a, b xml.Attr) int {
return cmp.Or(
Expand Down
29 changes: 29 additions & 0 deletions testdata/cubic01.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4b0b1c4

Please sign in to comment.