summaryrefslogtreecommitdiffstats
path: root/modules/html
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2022-11-08 23:13:58 +0800
committerGitHub <noreply@github.com>2022-11-08 23:13:58 +0800
commit2ebab429347f04330dab9de5a730e0296ba6524b (patch)
tree7c865578bbd332fec94d89646e2a219eef9bd4e6 /modules/html
parent91c7a3e66f16f42816784817017408b6b35fb585 (diff)
downloadgitea-2ebab429347f04330dab9de5a730e0296ba6524b.tar.gz
gitea-2ebab429347f04330dab9de5a730e0296ba6524b.zip
Move svg html render to modules/svg (#21716)
Also added more checks for the render function. Co-authored-by: silverwind <me@silverwind.io>
Diffstat (limited to 'modules/html')
-rw-r--r--modules/html/html.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/modules/html/html.go b/modules/html/html.go
new file mode 100644
index 0000000000..dafdb503b6
--- /dev/null
+++ b/modules/html/html.go
@@ -0,0 +1,34 @@
+// Copyright 2022 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package html
+
+// ParseSizeAndClass get size and class from string with default values
+// If present, "others" expects the new size first and then the classes to use
+func ParseSizeAndClass(defaultSize int, defaultClass string, others ...interface{}) (int, string) {
+ if len(others) == 0 {
+ return defaultSize, defaultClass
+ }
+
+ size := defaultSize
+ _size, ok := others[0].(int)
+ if ok && _size != 0 {
+ size = _size
+ }
+
+ if len(others) == 1 {
+ return size, defaultClass
+ }
+
+ class := defaultClass
+ if _class, ok := others[1].(string); ok && _class != "" {
+ if defaultClass == "" {
+ class = _class
+ } else {
+ class = defaultClass + " " + _class
+ }
+ }
+
+ return size, class
+}