parseSVGAttributes parses the root SVG element and returns its attributes.
(content string)
| 58 | |
| 59 | // parseSVGAttributes parses the root SVG element and returns its attributes. |
| 60 | func 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. |
| 78 | func parseAttributes(attrsStr string) map[string]string { |
no test coverage detected