aboutsummaryrefslogtreecommitdiffstats
path: root/modules/svg
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2023-03-21 13:39:27 +0800
committerGitHub <noreply@github.com>2023-03-21 13:39:27 +0800
commita797b8458e90caa00427d1270b82031c5e64ec09 (patch)
tree1c29e346f2d8810b8c08551a2e196e976ea26fe7 /modules/svg
parent34a2cf5079fb9537d1927ddc57cc3f9267a079fc (diff)
downloadgitea-a797b8458e90caa00427d1270b82031c5e64ec09.tar.gz
gitea-a797b8458e90caa00427d1270b82031c5e64ec09.zip
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>
Diffstat (limited to 'modules/svg')
-rw-r--r--modules/svg/svg.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/modules/svg/svg.go b/modules/svg/svg.go
index e0f0a263f3..b74ee35358 100644
--- a/modules/svg/svg.go
+++ b/modules/svg/svg.go
@@ -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)