Fix HTML_ATTR rendering (naive)
- was missing spaces between attributes when rendering to org - was duplicating attributes when rendering to html - now we join / replace attributes depending on the name - for now only class & style are appended
This commit is contained in:
parent
08ff3ac22e
commit
0a905ca172
6 changed files with 28 additions and 12 deletions
18
org/html.go
18
org/html.go
|
@ -316,8 +316,7 @@ func withHTMLAttributes(input string, kvs ...string) string {
|
|||
}
|
||||
out, node := strings.Builder{}, nodes[0]
|
||||
for i := 0; i < len(kvs)-1; i += 2 {
|
||||
k, v := strings.TrimPrefix(kvs[i], ":"), kvs[i+1]
|
||||
node.Attr = append(node.Attr, h.Attribute{Namespace: "", Key: k, Val: v})
|
||||
node.Attr = setHTMLAttribute(node.Attr, strings.TrimPrefix(kvs[i], ":"), kvs[i+1])
|
||||
}
|
||||
err = h.Render(&out, nodes[0])
|
||||
if err != nil {
|
||||
|
@ -325,3 +324,18 @@ func withHTMLAttributes(input string, kvs ...string) string {
|
|||
}
|
||||
return out.String()
|
||||
}
|
||||
|
||||
func setHTMLAttribute(attributes []h.Attribute, k, v string) []h.Attribute {
|
||||
for i, a := range attributes {
|
||||
if strings.ToLower(a.Key) == strings.ToLower(k) {
|
||||
switch strings.ToLower(k) {
|
||||
case "class", "style":
|
||||
attributes[i].Val += " " + v
|
||||
default:
|
||||
attributes[i].Val = v
|
||||
}
|
||||
return attributes
|
||||
}
|
||||
}
|
||||
return append(attributes, h.Attribute{Namespace: "", Key: k, Val: v})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue