A golang library with accompanying lsp for configurably parsing html sequences into stucts originally built for html tables, but can be used for any html sequence.
Enables data binding to structs and provides a simple, but dynamic way to define a table schema.
Install the package in a project with:
go get github.com/conneroisu/seltabl
Install the lsp with:
go install github.com/conneroisu/seltabl/tools/seltabls@latest
package main
import (
"fmt"
"github.com/conneroisu/seltabl"
"github.com/conneroisu/seltabl/testdata"
)
type TableStruct struct {
A string `json:"a" seltabl:"a" hSel:"tr:nth-child(1) td:nth-child(1)" dSel:"tr td:nth-child(1)" ctl:"text"`
B string `json:"b" seltabl:"b" hSel:"tr:nth-child(1) td:nth-child(2)" dSel:"tr td:nth-child(2)" ctl:"text"`
}
var fixture = `
<table>
<tr>
<td>a</td>
<td>b</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
<tr>
<td>5</td>
<td>6</td>
</tr>
<tr>
<td>7</td>
<td>8</td>
</tr>
</table>
`
func main() {
fss, err := seltabl.NewFromString[TableStruct](fixture)
if err != nil {
panic(fmt.Errorf("failed to parse html: %w", err))
}
for _, fs := range fss {
fmt.Printf("%+v\n", fs)
}
}
Output:
{A:1 B:2}
{A:3 B:4}
{A:5 B:6}
{A:7 B:8}
A makefile at the root of the project is provided to help with development.
One can run the tests with:
make test
One can run the linter with:
make lint
One can run the formatter with:
make fmt
One can run the documentation generator with:
make doc
MIT