https://github.com/nikolaydubina/htmlyaml
🐹 render YAML as HTML in Go
https://github.com/nikolaydubina/htmlyaml
code-editor code-visualisation data-visualisation go golang rendering text-formatting yaml
Last synced: 7 months ago
JSON representation
🐹 render YAML as HTML in Go
- Host: GitHub
- URL: https://github.com/nikolaydubina/htmlyaml
- Owner: nikolaydubina
- License: mit
- Created: 2023-03-18T14:16:35.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-03-21T11:36:14.000Z (over 1 year ago)
- Last Synced: 2024-05-01T14:34:55.644Z (over 1 year ago)
- Topics: code-editor, code-visualisation, data-visualisation, go, golang, rendering, text-formatting, yaml
- Language: Go
- Homepage:
- Size: 1.02 MB
- Stars: 4
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Codeowners: .github/CODEOWNERS
- Security: SECURITY.md
Awesome Lists containing this project
- awesome-go - htmlyaml - Rich rendering of YAML as HTML in Go (Text Processing / Markup Languages)
README
## 🐹 htmlyaml: rich rendering of YAML as HTML in Go
[](https://codecov.io/gh/nikolaydubina/htmlyaml)
[](https://goreportcard.com/report/github.com/nikolaydubina/htmlyaml)
[](https://pkg.go.dev/github.com/nikolaydubina/htmlyaml)
[](https://github.com/avelino/awesome-go)
[](https://securityscorecards.dev/viewer/?uri=github.com/nikolaydubina/htmlyaml)
* pure Go
* no Javascript
* no dependencies
* no `reflect`
* no `fmt`
* no `text/template`, `html/template`
* 300 LOC
* customizable rendering
* JSON Path for elements access

```go
// YAML has to be any
var v any
yaml.Unmarshal(exampleYAML, &v)
htmlPage := htmlyaml.DefaultPageMarshaler.Marshal(v)
```
```go
// 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 `
` + s + ``
}
if v > 10 {
return `` + s + ``
}
return `` + s + ``
}
m := htmlyaml.DefaultPageMarshaler
m.Marshaler = &s
// write HTML page
htmlPage := m.Marshal(v)
```
## Related Work
- https://github.com/alecthomas/chroma can render many languages into HTML with syntax highligting