// Copyright (c) 2009-2022 The MathJax Consortium// SPDX-License-Identifier: Apache-2.0//// This file is a Go translation and modification of MathJax 3.2.2.// Sources: ts/input/tex/base/BaseMethods.ts (MmlToken/MmlTokenAllow),// ts/input/tex/ParseUtil.ts (MmlFilterAttribute), and NodeUtil.ts.package teximport ()// JavaScript's non-Unicode /i [a-z] is ASCII, while its \s includes these// Unicode whitespace characters. Go's regexp shorthand classes differ.const mmlTokenSpace = `[\t\n\v\f\r \x{00A0}\x{1680}\x{2000}-\x{200A}\x{2028}\x{2029}\x{202F}\x{205F}\x{3000}\x{FEFF}]`var ( mmlTokenLeadingSpace = regexp.MustCompile(`^` + mmlTokenSpace + `+`) mmlTokenAttribute = regexp.MustCompile(`^([a-zA-Z]+)` + mmlTokenSpace + `*=` + mmlTokenSpace + `*('[^']*'|"[^"]*"|[^ ,]*)` + mmlTokenSpace + `*,?` + mmlTokenSpace + `*`))func mmlTokenAllowed( string) bool {switch {case"fontfamily", "fontsize", "fontweight", "fontstyle", "color", "background", "id", "class", "href", "style":returntrue }returnfalse}func ( *parser) ( string) ([]*mml.Node, error) { , , := .readArgument(, false)if != nil {returnnil, } , , := .readBrackets(nil)if != nil {var *Erroriferrors.As(, &) && .ID == "MissingCloseBracket" {returnnil, texError(.ID, "Could not find closing ']' for argument to %s", "\\"+) }returnnil, } = mmlTokenLeadingSpace.ReplaceAllString(, "") , , := .readArgument(, false)if != nil {returnnil, } , := texMMLFactory.Definition()if ! || !.Flags.Token {returnnil, texError("NotMathMLToken", "%s is not a token element", ) } := .noteMO(node())varmjSourceObjectvar []stringfor != "" { := mmlTokenAttribute.FindStringSubmatch()if == nil {returnnil, texError("InvalidMathMLAttr", "Invalid MathML attribute: %s", ) } := [1]if !.Attributes.HasDefault() && !mmlTokenAllowed() {returnnil, texError("UnknownAttrForElement", "%s is not a recognized attribute for %s", , ) } := [2]// The pinned unquote regexp uses '.', without dotAll. Quoted values // containing a JS line terminator therefore retain their quotes.iflen() >= 2 && ([0] == '\'' || [0] == '"') && [len()-1] == [0] && !strings.ContainsAny([1:len()-1], "\n\r\u2028\u2029") { = [1 : len()-1] }// MmlFilterAttribute is the identity function in the pinned package.if != "" {varany = ifstrings.ToLower() == "true" { = true } elseifstrings.ToLower() == "false" { = false } = append(, mjSourceProperty{Name: , Value: }) = append(, ) } = [len([0]):] }iflen() != 0 { = append(, mjSourceProperty{Name: "mjx-keep-attrs", Value: strings.Join(, " ")}) }// Upstream's inherited-attribute pass trims MmlMspace's text child to // its zero arity. Do not retain that child in the compiled token.if .Flags.Arity != 0 { .SetChildren([]*mml.Node{mml.NewText()}) }applySourceObject(, )return []*mml.Node{}, nil}
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.