htmgo/tools/html-to-htmgo/internal/adapters/services/formatter/formatter.go
maddalax 8736c00fd5
htmgo - custom formatter (#47)
* format htmgo elements on save

* formatter updates

* ensure we maintain comments
2024-10-25 10:33:48 -05:00

28 lines
480 B
Go

package formatter
import (
"github.com/maddalax/htmgo/tools/html-to-htmgo/internal/domain"
"go/format"
)
type Formatter struct {
}
func (f Formatter) Format(node *domain.CustomNode) string {
b := []byte(`package main
import (
"github.com/maddalax/htmgo/framework/h"
)
func MyComponent() *h.Element {
return ` + node.String() + `
}`)
dist, err := format.Source(b)
if err != nil {
return string(b)
}
return string(dist)
}
func New() Formatter {
return Formatter{}
}