package tex
import (
"unicode/utf8"
"github.com/d2lang/mathjax-go/internal/mml"
)
const vectorFactoryToken = "go-vector-factory-token"
const vectorFactoryDone = "go-vector-factory-done"
func (p *parser ) applyVectorFactory (n *mml .Node ) {
if !p .vectorFactory || n == nil {
return
}
n .Walk (func (current *mml .Node ) bool {
origin , _ := current .Property (vectorFactoryToken )
done , _ := current .Property (vectorFactoryDone )
if origin != true || done == true {
return true
}
current .SetProperty (vectorFactoryDone , true )
text := textContent (current )
r , size := utf8 .DecodeRuneInString (text )
if p .activeFont != "" || p .vectorFont == "" || size == 0 || size != len (text ) || r > 0xFFFF {
return true
}
accent , _ := current .Attributes .Get ("accent" )
selected := r >= 'A' && r <= 'Z' || r >= 'a' && r <= 'z' || r >= 0x391 && r <= 0x3A9 || r >= '0' && r <= '9' || p .vectorStar && r >= 0x3B1 && r <= 0x3C9 || accent == true
if selected {
current .Attributes .Set ("mathvariant" , p .vectorFont )
}
return true
})
}
func (p *parser ) parseVectorString (source string , star bool ) (*mml .Node , error ) {
count := p .state .macroCount
p .state .macroCount = 0
defer func () { p .state .macroCount = count }()
variant := "bold"
if star {
variant = "bold-italic"
}
sub := &parser {source : source , state : p .state , display : p .display , inRoot : p .inRoot , activeColor : p .activeColor ,
multiLetterFont : p .multiLetterFont , vectorFactory : true , vectorFont : variant , vectorStar : star ,
identifierPattern : p .identifierPattern , operatorLetters : p .operatorLetters , noAutoOP : p .noAutoOP ,
fontExplicitEmpty : false ,
genfracPalette : p .genfracPalette , starMacroChildren : p .starMacroChildren ,
derivativeChildren : p .derivativeChildren }
children , _ , err := sub .parseRow (0 , false )
if err != nil {
return nil , err
}
result := row (children , true )
result .Walk (func (n *mml .Node ) bool {
if n .Flags .Token {
n .SetProperty (resolvedFontScope , true )
}
return true
})
p .vectorFont = ""
p .vectorStar = false
p .fontExplicitEmpty = false
return result , nil
}
The pages are generated with Golds v0.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 .