Keep (add if not existing) xmlns attribute for generated SVG images (#23410)

Fix #23409 

Developers could browse & preview the local SVG images files directly.

It still has clear output.

![image](https://user-images.githubusercontent.com/2114189/224317107-f4b26c76-e36a-4e80-9eee-d8dc2e16421f.png)


![image](https://user-images.githubusercontent.com/2114189/224317527-2d4ca131-978c-4933-b071-4bae483f06e1.png)

---------

Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: delvh <leon@kske.dev>
This commit is contained in:
wxiaoguang 2023-03-21 13:39:27 +08:00 committed by GitHub
parent 34a2cf5079
commit a797b8458e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
343 changed files with 357 additions and 343 deletions

View file

@ -25,6 +25,12 @@ const defaultSize = 16
// Init discovers SVGs and populates the `SVGs` variable
func Init() {
SVGs = Discover()
// Remove `xmlns` because inline SVG does not need it
r := regexp.MustCompile(`(<svg\b[^>]*?)\s+xmlns="[^"]*"`)
for name, svg := range SVGs {
SVGs[name] = r.ReplaceAllString(svg, "$1")
}
}
// Render render icons - arguments icon name (string), size (int), class (string)