mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-29 10:57:44 +09:00 
			
		
		
		
	Refactor backend SVG package and add tests (#26335)
Introduce a well-tested `svg.Normalize` function. Make `RenderHTML` faster and more stable.
This commit is contained in:
		| @@ -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 | ||||
| 	} | ||||
|  | ||||
| 	class := defaultClass | ||||
| 	if _class, ok := others[1].(string); ok && _class != "" { | ||||
| 		if defaultClass == "" { | ||||
| 			class = _class | ||||
| 		} else { | ||||
| 			class = defaultClass + " " + _class | ||||
| 	if len(others) >= 1 { | ||||
| 		if v, ok := others[0].(int); ok && v != 0 { | ||||
| 			size = v | ||||
| 		} | ||||
| 	} | ||||
| 	class := defaultClass | ||||
| 	if len(others) >= 2 { | ||||
| 		if v, ok := others[1].(string); ok && v != "" { | ||||
| 			if class != "" { | ||||
| 				class += " " | ||||
| 			} | ||||
| 			class += v | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return size, class | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user