-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
98 additions
and
24 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 53 additions & 0 deletions
53
htmgo-site/md/docs/8_miscellaneous/1_tailwind_intellisense.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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\\(([^)]*)\\)", "[\"`]([^\"`]*)[\"`"] | ||
] | ||
} | ||
``` |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters