Diff
diff --git a/cstyle/transformers/text/main.go b/cstyle/transformers/text/main.go
index 488d64d..0b2fc68 100644
--- a/cstyle/transformers/text/main.go
+++ b/cstyle/transformers/text/main.go
@@ -21 +21 @@ func Init() cstyle.Transformer {
- if len(strings.TrimSpace(n.GetInnerText())) > 0 && !element.ChildrenHaveText(n) {
+ if len(strings.TrimSpace(n.InnerText)) > 0 && !element.ChildrenHaveText(n) {
@@ -31,2 +31,2 @@ func Init() cstyle.Transformer {
- words := strings.Split(strings.TrimSpace(DecodeHTMLEscapes(n.GetInnerText())), " ")
- n.SetInnerText("")
+ words := strings.Split(strings.TrimSpace(DecodeHTMLEscapes(n.InnerText)), " ")
+ n.InnerText = ""
@@ -34 +34 @@ func Init() cstyle.Transformer {
- n.SetInnerText(DecodeHTMLEscapes(words[0]))
+ n.InnerText = DecodeHTMLEscapes(words[0])
@@ -40,4 +40,4 @@ func Init() cstyle.Transformer {
- el.SetInnerText(words[a])
- // !CHECK: Idk if this breaks text
- // el.Parent = n
- // element.QuickStyles(&el)
+ el.InnerText = words[a]
+
+ el.Parent = n
+ element.QuickStyles(&el)
@@ -46 +46 @@ func Init() cstyle.Transformer {
- n.Parent().InsertAfter(&el, n)
+ InsertAfter(n.Parent, &el, n)
@@ -54,3 +54,3 @@ func Init() cstyle.Transformer {
- el.SetInnerText(words[i])
- // el.Parent = n
- // element.QuickStyles(&el)
+ el.InnerText = words[i]
+ el.Parent = n
+ element.QuickStyles(&el)
@@ -59 +59 @@ func Init() cstyle.Transformer {
- n.AppendChild(&el)
+ AppendChild(n, &el)
@@ -70,0 +71,23 @@ func DecodeHTMLEscapes(input string) string {
+
+func InsertAfter(n, c, tgt *element.Node) {
+ c.Properties.Id = element.GenerateUniqueId(n, c.TagName())
+ nodeIndex := -1
+ for i, v := range n.Children {
+ if v.Properties.Id == tgt.Properties.Id {
+ nodeIndex = i
+ break
+ }
+ }
+ if nodeIndex > -1 {
+ n.Children = append(n.Children, nil) // Extend the slice by one
+ copy(n.Children[nodeIndex+2:], n.Children[nodeIndex+1:]) // Shift elements to the right
+ n.Children[nodeIndex+1] = c // Insert the new node
+ } else {
+ AppendChild(n, c)
+ }
+}
+
+func AppendChild(n, c *element.Node) {
+ c.Properties.Id = element.GenerateUniqueId(n, c.TagName())
+ n.Children = append(n.Children, c)
+}