add tailwind intellisense notes
This commit is contained in:
parent
72e3383e75
commit
186bb7d14c
6 changed files with 98 additions and 24 deletions
BIN
htmgo-site/assets/public/tailwind-intellisense.png
Normal file
BIN
htmgo-site/assets/public/tailwind-intellisense.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 125 KiB |
|
|
@ -0,0 +1,53 @@
|
||||||
|
### Tailwind intellisense
|
||||||
|
|
||||||
|
Tailwind's language server allows you to specify custom configuration on what it should match to start giving you tailwind intellisense.
|
||||||
|
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
To make this work, you will need to update the tailwind lsp config with the config below:
|
||||||
|
|
||||||
|
Main thing to note here is
|
||||||
|
1. "go" is added to the includeLanguages list
|
||||||
|
2. classRegex is updated to match the tailwind classes in the go code.
|
||||||
|
|
||||||
|
### Jetbrains IDE's (GoLand)
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"includeLanguages": {
|
||||||
|
"go": "html"
|
||||||
|
},
|
||||||
|
"experimental": {
|
||||||
|
"configFile": null,
|
||||||
|
"classRegex": [
|
||||||
|
["Class\\(([^)]*)\\)", "[\"`]([^\"`]*)[\"`]"],
|
||||||
|
["ClassX\\(([^)]*)\\)", "[\"`]([^\"`]*)[\"`]"],
|
||||||
|
["ClassIf\\(([^)]*)\\)", "[\"`]([^\"`]*)[\"`]"],
|
||||||
|
["Classes\\(([^)]*)\\)", "[\"`]([^\"`]*)[\"`]"]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
To find this configuration in GoLand you can go to `Settings -> Languages & Frameworks -> Style Sheets -> Tailwind CSS` and update the configuration there.
|
||||||
|
These changes are additive, add these options to your existing tailwind lsp config, instead of replacing the entire file.
|
||||||
|
|
||||||
|
See more: https://github.com/tailwindlabs/tailwindcss/issues/7553#issuecomment-735915659
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
### Visual Studio Code
|
||||||
|
For VSCode, you should be able to update your settings.json with the following values:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"tailwindCSS.includeLanguages": {
|
||||||
|
"go": "html"
|
||||||
|
},
|
||||||
|
"tailwindCSS.experimental.classRegex": [
|
||||||
|
["Class\\(([^)]*)\\)", "[\"`]([^\"`]*)[\"`]"],
|
||||||
|
["ClassX\\(([^)]*)\\)", "[\"`]([^\"`]*)[\"`]"],
|
||||||
|
["ClassIf\\(([^)]*)\\)", "[\"`]([^\"`]*)[\"`]"],
|
||||||
|
["Classes\\(([^)]*)\\)", "[\"`]([^\"`]*)[\"`"]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
@ -1,34 +1,18 @@
|
||||||
package partials
|
package partials
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"github.com/alecthomas/chroma/v2"
|
|
||||||
"github.com/alecthomas/chroma/v2/formatters/html"
|
|
||||||
"github.com/alecthomas/chroma/v2/lexers"
|
|
||||||
"github.com/alecthomas/chroma/v2/styles"
|
|
||||||
"github.com/maddalax/htmgo/framework/h"
|
"github.com/maddalax/htmgo/framework/h"
|
||||||
"github.com/maddalax/htmgo/tools/html-to-htmgo/htmltogo"
|
"github.com/maddalax/htmgo/tools/html-to-htmgo/htmltogo"
|
||||||
|
"htmgo-site/ui"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ConvertHtmlToGo(ctx *h.RequestContext) *h.Partial {
|
func ConvertHtmlToGo(ctx *h.RequestContext) *h.Partial {
|
||||||
value := ctx.FormValue("html-input")
|
value := ctx.FormValue("html-input")
|
||||||
parsed := htmltogo.Parse([]byte(value))
|
parsed := htmltogo.Parse([]byte(value))
|
||||||
|
|
||||||
var buf bytes.Buffer
|
formatted := ui.FormatCode(string(parsed), "height: 100%;")
|
||||||
|
|
||||||
lexer := lexers.Get("go")
|
return h.SwapPartial(ctx, GoOutput(formatted))
|
||||||
style := styles.Get("github")
|
|
||||||
formatter := html.New(html.WithCustomCSS(map[chroma.TokenType]string{
|
|
||||||
chroma.PreWrapper: "padding: 12px; height: 100%; overflow: auto;",
|
|
||||||
}))
|
|
||||||
iterator, err := lexer.Tokenise(nil, string(parsed))
|
|
||||||
err = formatter.Format(&buf, style, iterator)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return h.SwapPartial(ctx, GoOutput(string(parsed)))
|
|
||||||
}
|
|
||||||
|
|
||||||
return h.SwapPartial(ctx, GoOutput(buf.String()))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func HtmlInput() *h.Element {
|
func HtmlInput() *h.Element {
|
||||||
|
|
@ -36,6 +20,7 @@ func HtmlInput() *h.Element {
|
||||||
h.Class("h-[90%] w-1/2 min-w-1/2"),
|
h.Class("h-[90%] w-1/2 min-w-1/2"),
|
||||||
h.TextArea(
|
h.TextArea(
|
||||||
h.Name("html-input"),
|
h.Name("html-input"),
|
||||||
|
h.MaxLength(500*1000),
|
||||||
h.PostPartial(ConvertHtmlToGo, "keyup delay:300ms"),
|
h.PostPartial(ConvertHtmlToGo, "keyup delay:300ms"),
|
||||||
h.Class("h-[90%] w-full p-4 rounded border border-slate-200"),
|
h.Class("h-[90%] w-full p-4 rounded border border-slate-200"),
|
||||||
h.Placeholder("Paste your HTML here"),
|
h.Placeholder("Paste your HTML here"),
|
||||||
|
|
|
||||||
34
htmgo-site/ui/snippet.go
Normal file
34
htmgo-site/ui/snippet.go
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
package ui
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"github.com/alecthomas/chroma/v2"
|
||||||
|
"github.com/alecthomas/chroma/v2/formatters/html"
|
||||||
|
"github.com/alecthomas/chroma/v2/lexers"
|
||||||
|
"github.com/alecthomas/chroma/v2/styles"
|
||||||
|
"github.com/maddalax/htmgo/framework/h"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func FormatCode(code string, customStyles ...string) string {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
lexer := lexers.Get("go")
|
||||||
|
style := styles.Get("github")
|
||||||
|
formatter := html.New(
|
||||||
|
html.WithCustomCSS(map[chroma.TokenType]string{
|
||||||
|
chroma.PreWrapper: fmt.Sprintf("padding: 12px; overflow: auto; %s", strings.Join(customStyles, ";")),
|
||||||
|
}))
|
||||||
|
iterator, err := lexer.Tokenise(nil, code)
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
err = formatter.Format(&buf, style, iterator)
|
||||||
|
return buf.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func CodeSnippet(code string) *h.Element {
|
||||||
|
return h.Div(
|
||||||
|
h.UnsafeRaw(FormatCode(code)),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -38,9 +38,11 @@
|
||||||
},
|
},
|
||||||
"experimental": {
|
"experimental": {
|
||||||
"configFile": null,
|
"configFile": null,
|
||||||
"classRegex": [[
|
"classRegex": [
|
||||||
"Class|h.Class\\(([^)]*)\\)",
|
["Class\\(([^)]*)\\)", "[\"`]([^\"`]*)[\"`]"],
|
||||||
"[\"'`]([^\"'`]*).*?[\"'`]"
|
["ClassX\\(([^)]*)\\)", "[\"`]([^\"`]*)[\"`]"],
|
||||||
]]
|
["ClassIf\\(([^)]*)\\)", "[\"`]([^\"`]*)[\"`]"],
|
||||||
|
["Classes\\(([^)]*)\\)", "[\"`]([^\"`]*)[\"`]"]
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue