🐹 htmlyaml: rich rendering of YAML as HTML in Go
![OpenSSF Scorecard](https://camo.githubusercontent.com/03f020d9c86418c37923f0300699b9a0e482517460694a68ab32c670cd7c358a/68747470733a2f2f6170692e736563757269747973636f726563617264732e6465762f70726f6a656374732f6769746875622e636f6d2f6e696b6f6c6179647562696e612f68746d6c79616d6c2f6261646765)
- pure Go
- no Javascript
- no dependencies
- no
reflect
- no
fmt
- no
text/template
, html/template
- 300 LOC
- customizable rendering
- JSON Path for elements access
![](https://raw.githubusercontent.com/nikolaydubina/htmlyaml/master/./doc/example-color.png)
// YAML has to be any
var v any
yaml.Unmarshal(exampleYAML, &v)
htmlPage := htmlyaml.DefaultPageMarshaler.Marshal(v)
// YAML has to be any
var v any
yaml.Unmarshal(exampleYAML, &v)
// customize how to render HTML elements
s := htmlyaml.DefaultMarshaler
s.Number = func(k string, v float64, s string) string {
if k == "$.cakes.strawberry-cake.size" {
return `<div class="yaml-value yaml-number" style="color:red;">` + s + `</div>`
}
if v > 10 {
return `<div class="yaml-value yaml-number" style="color:blue;">` + s + `</div>`
}
return `<div class="yaml-value yaml-number">` + s + `</div>`
}
m := htmlyaml.DefaultPageMarshaler
m.Marshaler = &s
// write HTML page
htmlPage := m.Marshal(v)