MCPcopy Create free account
hub / github.com/coder/coder / parseSVGAttributes

Function parseSVGAttributes

scripts/gensite/generate_icon_list_test.go:60–75  ·  view source on GitHub ↗

parseSVGAttributes parses the root SVG element and returns its attributes.

(content string)

Source from the content-addressed store, hash-verified

58
59// parseSVGAttributes parses the root SVG element and returns its attributes.
60func parseSVGAttributes(content string) (map[string]string, error) {
61 // Match the opening <svg> tag with optional attributes
62 svgTagRegex := regexp.MustCompile(`<svg(\s+[^>]*)?>`)
63 matches := svgTagRegex.FindStringSubmatch(content)
64 if len(matches) == 0 {
65 return nil, xerrors.New("no <svg> tag found")
66 }
67
68 var attrsStr string
69 if len(matches) >= 2 && matches[1] != "" {
70 attrsStr = strings.TrimSpace(matches[1])
71 }
72
73 attrs := parseAttributes(attrsStr)
74 return attrs, nil
75}
76
77// parseAttributes parses a string of XML attributes into a map.
78func parseAttributes(attrsStr string) map[string]string {

Callers 1

TestSVGIconAttributesFunction · 0.85

Calls 3

parseAttributesFunction · 0.85
MustCompileMethod · 0.80
NewMethod · 0.65

Tested by

no test coverage detected