1.2 KiB
1.2 KiB
Htmgo Format
htmgo has a built-in formatter that can be used to format htmgo element blocks.
It is available through the 'htmgo' cli tool that is installed with htmgo.
Note: if you have previously installed htmgo, you will need to run GOPROXY=direct go install github.com/maddalax/htmgo/cli/htmgo@latest to update the cli tool.
To use it, run the following command:
// format all .go files in the current directory recursively
htmgo format .
// format the file specified
htmgo format ./my-file.go
This will format all htmgo element blocks in your project.
Example:
h.Div(
h.Class("flex gap-2"), h.Text("hello"), h.Text("world"),
)
Output:
h.Div(
h.Class("flex gap-2"),
h.Text("hello"),
h.Text("world"),
)
Running htmgo format on save
Jetbrains IDE's
-
Go to Settings -> Tools -> File Watchers -> + custom
-
Set the following values:
Name: htmgo format
File Type: Go
Scope: Current File
Program: htmgo
Arguments: format $FilePath$
Output paths to refresh: $FilePath$
Working directory: $ProjectFileDir$
-
Save the file watcher and ensure it is enabled
-
Go to
Settings -> Tools -> Actions On Saveand ensure thehtmgo formataction is enabled