package tex
import (
"unicode/utf16"
"github.com/d2lang/mathjax-go/internal/mml"
)
func notRemap(text string ) (string , bool ) {
for i := len (mjSourceMaps ) - 1 ; i >= 0 ; i -- {
m := mjSourceMaps [i ]
if m .Name != "not_remap" || m .Kind != mjSourceCharacterMap {
continue
}
for j := len (m .Entries ) - 1 ; j >= 0 ; j -- {
entry := m .Entries [j ]
if entry .Name == text {
value , ok := entry .Value .(string )
return value , ok
}
}
return "" , false
}
return "" , false
}
func notFallback() *mml .Node {
text := node ("mtext" , mml .NewText ("\u29F8" ))
padded := node ("mpadded" , text )
padded .Attributes .Set ("width" , 0 )
return texAtom (padded , mml .TeXClassRel )
}
func applyNotToken(n *mml .Node ) bool {
if n == nil || (n .Kind != "mo" && n .Kind != "mi" && n .Kind != "mtext" ) || len (n .Children ) != 1 {
return false
}
text := textContent (n )
moves , _ := n .Property ("movesupsub" )
if len (utf16 .Encode ([]rune (text ))) != 1 || limitsTruthy (moves ) {
return false
}
if replacement , ok := notRemap (text ); ok {
child := mml .NewText (replacement )
n .Children [0 ] = child
child .Parent = n
} else {
n .AppendChild (mml .NewText ("\u0338" ))
}
return true
}
type pendingNot bool
func (pending *pendingNot ) finish () []*mml .Node {
if !*pending {
return nil
}
*pending = false
return []*mml .Node {notFallback ()}
}
func (pending *pendingNot ) start () []*mml .Node {
nodes := pending .finish ()
*pending = true
return nodes
}
func (pending *pendingNot ) apply (nodes []*mml .Node ) []*mml .Node {
if !*pending || len (nodes ) == 0 {
return nodes
}
*pending = false
if applyNotToken (nodes [0 ]) {
return nodes
}
return append ([]*mml .Node {notFallback ()}, nodes ...)
}
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 .