-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathattr.go
More file actions
34 lines (29 loc) · 701 Bytes
/
Copy pathattr.go
File metadata and controls
34 lines (29 loc) · 701 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package obsidian
import (
"bytes"
"slices"
gast "github.com/yuin/goldmark/ast"
)
var (
attrNameID = []byte("id") // Const.
attrNameClass = []byte("class") // Const.
)
func appendClass(n gast.Node, class []byte) {
if len(class) == 0 { // Make it easier to use configurable empty class names.
return
}
val, found := n.Attribute(attrNameClass)
if !found {
n.SetAttribute(attrNameClass, bytes.Clone(class))
} else {
value := val.([]byte)
for existing := range bytes.FieldsSeq(value) {
if bytes.Equal(class, existing) {
return
}
}
value = slices.Grow(value, 1+len(class))
value = append(append(value, ' '), class...)
n.SetAttribute(attrNameClass, value)
}
}