treeificator/README.md
mStar 4368f7713e
Fix parser invalid results, add tests, readme
- Fix parser not producing the correct results
- Add tests for everything
- Add readme with example

Ready for v1
2025-05-02 15:18:14 +02:00

44 lines
1.3 KiB
Markdown

# Treeificator
![Go Coverage](https://git.mstar.dev/mstar/treeificator/raw/branch/main/coverage_badge.png)
[![license](http://img.shields.io/badge/license-MIT-red.svg?style=flat)](https://git.mstar.dev/mstar/treeificator/src/branch/main/LICENSE)
[![Go Documentation](https://godocs.io/git.mstar.dev/mstar/treeificator?status.svg)](https://godocs.io/git.mstar.dev/mstar/treeificator)
[![GoDoc](https://pkg.go.dev/badge/git.mstar.dev/mstar/treeificator)](https://pkg.go.dev/git.mstar.dev/mstar/treeificator)
A small module to turn a string into a tree of nodes based on a list of informers.
## How to use
First import the module `go get git.mstar.dev/mstar/treeificator`
Then define the informers for the beginning and end of each node type you want
```go
type PInformer struct{}
// The prefix starting a block of type PInformer
func (p *PInformer) GetPrefix() string {
return "<p>"
}
// The suffix ending a block of type PInformer
func (p *PInformer) GetSuffix() string {
return "</p>"
}
// The name of PInformer
func (p *PInformer) GetName() string {
return "p-element"
}
```
And finally parse any string
```go
import "git.mstar.dev/mstar/treeificator"
treeRoot := treeificator.Marshal(yourString, &PInformer{})
```
See [documentation](https://pkg.go.dev/git.mstar.dev/mstar/treeificator)
for more details