Files
marqdo/plugins/web/internal/style/style.go
cflmyandCursor 7a0309284a feat(web): Go plugin W-G1 assemble/render + SQLite smoke path
Port table/compose/style/render/db/form/app bags, register ABI symbols,
prefer MARQDO_WEB_PLUGIN over ~/.marqdo, and pass web-smoke + web-zh-smoke.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-10 15:27:12 +08:00

64 lines
1.2 KiB
Go

// Package style implements web_style (CSS from GFM style tables).
package style
import (
"strconv"
"strings"
"github.com/marqdo/marqdo/plugins/web/internal/table"
)
// Style matches Rust web_style: args name + table + optional strict → CSS string.
func Style(args map[string]any) (string, error) {
name := ""
if v, ok := args["name"]; ok && v != nil {
name = cellStr(v)
}
var tbl any = []any{}
if v, ok := args["table"]; ok && v != nil {
tbl = v
}
strict := false
for _, k := range []string{"strict", "strict_css_cells", "严格"} {
if v, ok := args[k]; ok {
strict = boolishStrict(v)
break
}
}
return table.AsCSSNamedChecked(name, tbl, strict)
}
func cellStr(v any) string {
switch t := v.(type) {
case string:
return t
case float64:
if t == float64(int64(t)) {
return strconv.FormatInt(int64(t), 10)
}
return strconv.FormatFloat(t, 'f', -1, 64)
case bool:
return strconv.FormatBool(t)
default:
return ""
}
}
func boolishStrict(v any) bool {
switch t := v.(type) {
case bool:
return t
case float64:
return int64(t) != 0
case string:
s := strings.TrimSpace(t)
switch s {
case "1", "true", "True", "yes", "on", "真", "是":
return true
}
return false
default:
return false
}
}