diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2023-08-05 12:34:59 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-05 04:34:59 +0000 |
commit | 5db4c8db93de9e8792ff4fb07adb8a23b65b7850 (patch) | |
tree | d1bbeb7b01854e588f60f83134895995229158fb /modules/html | |
parent | 12c249c5ca3d719850831c113ec1998d2124b860 (diff) | |
download | gitea-5db4c8db93de9e8792ff4fb07adb8a23b65b7850.tar.gz gitea-5db4c8db93de9e8792ff4fb07adb8a23b65b7850.zip |
Refactor backend SVG package and add tests (#26335)
Introduce a well-tested `svg.Normalize` function.
Make `RenderHTML` faster and more stable.
Diffstat (limited to 'modules/html')
-rw-r--r-- | modules/html/html.go | 28 |
1 files changed, 10 insertions, 18 deletions
diff --git a/modules/html/html.go b/modules/html/html.go index 6cb6b847ef..b1ebd584c6 100644 --- a/modules/html/html.go +++ b/modules/html/html.go @@ -6,28 +6,20 @@ 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 ...any) (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 + if len(others) >= 1 { + if v, ok := others[0].(int); ok && v != 0 { + size = v + } } - class := defaultClass - if _class, ok := others[1].(string); ok && _class != "" { - if defaultClass == "" { - class = _class - } else { - class = defaultClass + " " + _class + if len(others) >= 2 { + if v, ok := others[1].(string); ok && v != "" { + if class != "" { + class += " " + } + class += v } } - return size, class } |