lazy initialize html5entities

This commit is contained in:
yuin 2024-10-12 22:37:57 +09:00
parent 697e44ce88
commit 3847ca20c6
2 changed files with 2140 additions and 2127 deletions

View file

@ -6,7 +6,7 @@ require (
github.com/88250/lute v1.7.5
github.com/gomarkdown/markdown v0.0.0-20230322041520-c84983bdbf2a
github.com/russross/blackfriday/v2 v2.1.0
github.com/yuin/goldmark v1.2.1
github.com/yuin/goldmark v0.0.0
gitlab.com/golang-commonmark/markdown v0.0.0-20211110145824-bf3e522c626a
)
@ -22,3 +22,4 @@ require (
)
replace gopkg.in/russross/blackfriday.v2 v2.0.1 => github.com/russross/blackfriday/v2 v2.0.1
replace github.com/yuin/goldmark v0.0.0 => ../../

View file

@ -1,6 +1,8 @@
//nolint:golint,lll,misspell
package util
import "sync"
// An HTML5Entity struct represents HTML5 entitites.
type HTML5Entity struct {
Name string
@ -11,11 +13,18 @@ type HTML5Entity struct {
// LookUpHTML5EntityByName returns (an HTML5Entity, true) if an entity named
// given name is found, otherwise (nil, false).
func LookUpHTML5EntityByName(name string) (*HTML5Entity, bool) {
v, ok := html5entities[name]
v, ok := html5entities()[name]
return v, ok
}
var html5entities = map[string]*HTML5Entity{
var html5entitiesOnce sync.Once // TODO: uses sync.OnceValue for future
var _html5entities map[string]*HTML5Entity
func html5entities() map[string]*HTML5Entity {
html5entitiesOnce.Do(func() {
_html5entities =
map[string]*HTML5Entity{
"AElig": {Name: "AElig", CodePoints: []int{198}, Characters: []byte{0xc3, 0x86}},
"AMP": {Name: "AMP", CodePoints: []int{38}, Characters: []byte{0x26}},
"Aacute": {Name: "Aacute", CodePoints: []int{193}, Characters: []byte{0xc3, 0x81}},
@ -2141,3 +2150,6 @@ var html5entities = map[string]*HTML5Entity{
"zwj": {Name: "zwj", CodePoints: []int{8205}, Characters: []byte{0xe2, 0x80, 0x8d}},
"zwnj": {Name: "zwnj", CodePoints: []int{8204}, Characters: []byte{0xe2, 0x80, 0x8c}},
}
})
return _html5entities
}