diff --git a/cstyle/transformers/text/main.go b/cstyle/transformers/text/main.go
index d02009a..149558d 100644
--- a/cstyle/transformers/text/main.go
+++ b/cstyle/transformers/text/main.go
@@ -20,2 +20,2 @@ func Init() cstyle.Transformer {
- Handler: func(n *element.Node, c *cstyle.CSS) *element.Node {
- if utils.IsParent(*n, "head") {
+ Handler: func(n element.Node, c *cstyle.CSS) element.Node {
+ if utils.IsParent(n, "head") {
@@ -34 +34 @@ func Init() cstyle.Transformer {
- el.Parent = n
+ el.Parent = &n
@@ -39 +39,8 @@ func Init() cstyle.Transformer {
- n.Parent.InsertAfter(&el, n)
+ isLast := "false"
+ if a == 0 {
+ isLast = "true"
+ }
+ el.SetAttribute("last", isLast)
+
+ n.Parent.InsertAfter(el, n)
+
@@ -48 +55 @@ func Init() cstyle.Transformer {
- el.Parent = n
+ el.Parent = &n
@@ -54 +61,7 @@ func Init() cstyle.Transformer {
- n.AppendChild(&el)
+ isLast := "false"
+ if i == len(words)-1 {
+ isLast = "true"
+ }
+ el.SetAttribute("last", isLast)
+
+ n.AppendChild(el)
package text
import (
"gui/cstyle"
"gui/element"
"gui/utils"
"html"
"strings"
)
func Init() cstyle.Transformer {
return cstyle.Transformer{
Selector: func(n *element.Node) bool {
if !utils.ChildrenHaveText(n) && len(strings.TrimSpace(n.InnerText)) > 0 {
return true
} else {
return false
}
},
Handler: func(n *element.Node, c *cstyle.CSS) *element.Node {
if utils.IsParent(*n, "head") {
return n
}
words := strings.Split(strings.TrimSpace(n.InnerText), " ")
n.InnerText = ""
if n.Style["display"] == "inline" {
n.InnerText = DecodeHTMLEscapes(words[0])
for i := 0; i < len(words)-1; i++ {
// Add the words backwards because you are inserting adjacent to the parent
a := (len(words) - 1) - i
if len(strings.TrimSpace(words[a])) > 0 {
el := n.CreateElement("notaspan")
el.InnerText = DecodeHTMLEscapes(words[a])
el.Parent = n
el.Style = c.QuickStyles(&el)
el.Style["display"] = "inline"
n.Parent.InsertAfter(&el, n)
}
}
} else {
for i := 0; i < len(words); i++ {
if len(strings.TrimSpace(words[i])) > 0 {
el := n.CreateElement("notaspan")
el.InnerText = DecodeHTMLEscapes(words[i])
el.Parent = n
el.Style = c.QuickStyles(&el)
el.Style["display"] = "inline"
el.Style["font-size"] = "1em"
n.AppendChild(&el)
}
}
}
return n
},
}
}
func DecodeHTMLEscapes(input string) string {
return html.UnescapeString(input)
}