diff --git a/cstyle/transformers/ol/main.go b/cstyle/transformers/ol/main.go
index 8d09bd1..b37b9f2 100644
--- a/cstyle/transformers/ol/main.go
+++ b/cstyle/transformers/ol/main.go
@@ -29,4 +29,4 @@ func Init() cstyle.Transformer {
- for k, v := range v.ComputedStyle {
- li.ComputedStyle[k] = v
- dot.ComputedStyle[k] = v
- content.ComputedStyle[k] = v
+ for k, v := range v.Styles() {
+ li.SetStyle(k, v)
+ dot.SetStyle(k, v)
+ content.SetStyle(k, v)
@@ -35,2 +35,2 @@ func Init() cstyle.Transformer {
- li.ComputedStyle["display"] = "flex"
- li.ComputedStyle["align-items"] = "center"
+ li.SetStyle("display", "flex")
+ li.SetStyle("align-items", "center")
@@ -38,2 +38,2 @@ func Init() cstyle.Transformer {
- dot.ComputedStyle["margin-right"] = "6px"
- dot.ComputedStyle["display"] = "block"
+ dot.SetStyle("margin-right", "6px")
+ dot.SetStyle("display", "block")
@@ -43 +43 @@ func Init() cstyle.Transformer {
- if n.ComputedStyle["font-style"] == "italic" {
+ if n.GetStyle("font-style") == "italic" {
@@ -51 +51 @@ func Init() cstyle.Transformer {
- fs := utils.ConvertToPixels(n.ComputedStyle["font-size"], 16, c.Width)
+ fs := utils.ConvertToPixels(n.GetStyle("font-size"), 16, c.Width)
@@ -54 +54 @@ func Init() cstyle.Transformer {
- fid := n.ComputedStyle["font-family"] + fmt.Sprint(em, n.ComputedStyle["font-weight"], italic)
+ fid := n.GetStyle("font-family") + fmt.Sprint(em, n.GetStyle("font-weight"), italic)
@@ -56 +56 @@ func Init() cstyle.Transformer {
- f, err := font.LoadFont(n.ComputedStyle["font-family"], int(em), n.ComputedStyle["font-weight"], italic, &c.Adapter.FileSystem)
+ f, err := font.LoadFont(n.GetStyle("font-family"), int(em), n.GetStyle("font-weight"), italic, &c.Adapter.FileSystem)
@@ -73 +73 @@ func Init() cstyle.Transformer {
- content.ComputedStyle["display"] = "block"
+ content.SetStyle("display", "block")
@@ -83 +83 @@ func Init() cstyle.Transformer {
- tN.Children[i].Children[0].ComputedStyle["margin-left"] = strconv.Itoa((maxOS - widths[i])) + "px"
+ tN.Children[i].Children[0].SetStyle("margin-left", strconv.Itoa((maxOS-widths[i]))+"px")
package ol
import (
"fmt"
"grim/cstyle"
"grim/element"
"grim/font"
"grim/utils"
"strconv"
imgFont "golang.org/x/image/font"
)
func Init() cstyle.Transformer {
return cstyle.Transformer{
Selector: func(n *element.Node, c *cstyle.CSS) bool {
return n.TagName == "ol"
},
Handler: func(n *element.Node, c *cstyle.CSS) *element.Node {
tN := n.CreateElement(n.TagName)
var maxOS int
var widths []int
// !ISSUE: Update this to match ul
for i, v := range n.Children {
li := n.CreateElement("li")
dot := li.CreateElement("div")
content := li.CreateElement("div")
for k, v := range v.ComputedStyle {
li.ComputedStyle[k] = v
dot.ComputedStyle[k] = v
content.ComputedStyle[k] = v
}
li.ComputedStyle["display"] = "flex"
li.ComputedStyle["align-items"] = "center"
dot.ComputedStyle["margin-right"] = "6px"
dot.ComputedStyle["display"] = "block"
italic := false
if n.ComputedStyle["font-style"] == "italic" {
italic = true
}
if c.Fonts == nil {
c.Fonts = map[string]imgFont.Face{}
}
fs := utils.ConvertToPixels(n.ComputedStyle["font-size"], 16, c.Width)
em := fs
fid := n.ComputedStyle["font-family"] + fmt.Sprint(em, n.ComputedStyle["font-weight"], italic)
if c.Fonts[fid] == nil {
f, err := font.LoadFont(n.ComputedStyle["font-family"], int(em), n.ComputedStyle["font-weight"], italic, &c.Adapter.FileSystem)
if err != nil {
panic(err)
}
c.Fonts[fid] = f
}
fnt := c.Fonts[fid]
w, _ := font.MeasureText(&font.MetaData{Font: &fnt}, strconv.Itoa(i+1)+".")
widths = append(widths, w)
if w > maxOS {
maxOS = w
}
dot.InnerText = strconv.Itoa(i+1) + "."
content.InnerText = v.InnerText
content.ComputedStyle["display"] = "block"
li.AppendChild(&dot)
li.AppendChild(&content)
li.Parent = n
tN.AppendChild(&li)
}
for i := range tN.Children {
tN.Children[i].Children[0].ComputedStyle["margin-left"] = strconv.Itoa((maxOS - widths[i])) + "px"
}
n.Children = tN.Children
return n
},
}
}