// Copyright (c) 2018-2022 Omar Al-Ithawi and The MathJax Consortium// SPDX-License-Identifier: Apache-2.0// Go translation and modification of MathJax 3.2.2 ColorMethods.ts.package colorimport ()var ( parseFloatPrefix = regexp.MustCompile(`^[+-]?(?:Infinity|(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)`) trailingUnit = regexp.MustCompile(`[a-z]*$`))// PaddingProperties ports ColorMethods.ts's padding() helper. Attribute order// matches the source PropertyList so a core parser can apply it directly to an// mpadded node.func ( string) []spec.Attribute { := "+" + := paddingUnit() := 2 * parseFloat()return []spec.Attribute{ {Name: "width", Value: "+" + jscompat.NumberString() + }, {Name: "height", Value: }, {Name: "depth", Value: }, {Name: "lspace", Value: }, }}func paddingUnit( string) string {// JavaScript's dot does not match line terminators, so the source // /^.*?([a-z]*)$/ replacement leaves such a value entirely unchanged.ifstrings.ContainsAny(, "\n\r\u2028\u2029") {return }returntrailingUnit.FindString()}func parseFloat( string) float64 { := parseFloatPrefix.FindString()if == "" {returnmath.NaN() }if == "+Infinity" || == "Infinity" {returnmath.Inf(1) }if == "-Infinity" {returnmath.Inf(-1) } , := strconv.ParseFloat(, 64)if != nil && !math.IsInf(, 0) {returnmath.NaN() }return}
The pages are generated with Goldsv0.8.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.