mirror of
https://github.com/russross/blackfriday.git
synced 2024-03-22 13:40:34 +08:00
Avoid calling bytes.Split() in appendLanguageAttr
This avoids some allocs.
This commit is contained in:
parent
9357a8f949
commit
22a3e5b744
11
html.go
11
html.go
|
@ -307,11 +307,14 @@ func isSmartypantable(node *Node) bool {
|
|||
}
|
||||
|
||||
func appendLanguageAttr(attrs []string, info []byte) []string {
|
||||
infoWords := bytes.Split(info, []byte("\t "))
|
||||
if len(infoWords) > 0 && len(infoWords[0]) > 0 {
|
||||
attrs = append(attrs, fmt.Sprintf("class=\"language-%s\"", infoWords[0]))
|
||||
if len(info) == 0 {
|
||||
return attrs
|
||||
}
|
||||
return attrs
|
||||
endOfLang := bytes.IndexAny(info, "\t ")
|
||||
if endOfLang < 0 {
|
||||
endOfLang = len(info)
|
||||
}
|
||||
return append(attrs, fmt.Sprintf("class=\"language-%s\"", info[:endOfLang]))
|
||||
}
|
||||
|
||||
func (r *HTMLRenderer) tag(w io.Writer, name []byte, attrs []string) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user