3 ms·
[off-topic comment but somewhat relevant for anyone choosing a lang/ecosystem] I noticed that the syntax highlighting for the Go html/template examples in the
by lucideer 2y ago
[off-topic comment but somewhat relevant for anyone choosing a lang/ecosystem]
I noticed that the syntax highlighting for the Go html/template examples in the article is incomplete. We're using Go html/templates on a new project (within a team that does a lot of React frontend & some Python) so this kind of project seems like it would really suit, but a massive bugbear has been the very poor IDE-level syntax highlighting support for Go html/templates. Can anyone recommend a good syntax highlighter for Go html/template in VSCode for example? None of the main/official/popular addons seem to get this right.
Seems a pretty unexpected oversight from a language from Google.
- rkwz 2y ago> I noticed that the syntax highlighting for the Go html/template examples in the article is incomplete. Sorry, it might be something wrong with my blog setup. I use hexo, might need to play around with the config. I use this VSCode extension for coding and it works fairly well: https://marketplace.visualstudio.com/items?itemName=jinliming2.vscode-go-template https://marketplace.visualstudio.com/items?itemName=jinlimin...
- catlifeonmars 2y agoThis is something that should be part of gopls IMO.
- dabber21 2y agothere are also projects that let you use HTML directly in Go like: https://www.gomponents.com/ https://www.gomponents.com/ (I'm currently using it in a side project and liking it so far, but I also just started)
- markusw 2y agoHey, I wrote that! :D I hope you find it useful.
- impune 2y agoIn Jet Brains family IDEs (not sure how they call the go one) you can use Inject language or reference option to get most of editor support (inspections,highlighting,intellisense etc.) for snippets of one language embedd in files of another language. I've been using it with JS scripts inside custom xml for a while and it works pretty well.
- michaelcampbell 2y agoThanks for this; JetBrains stuff continues to amaze me. Its blessing and curse is the incredible breadth of functionality I keep learning about.
- lucideer 2y agoJetBrains "Inject" is fine for contiguous embeds like JS in XML, but doesn't cut it for inline intertwined string-templating. E.g. (from the article): <a class="button {{if .IsPrimary}}primary{{end}}" {{if eq .IsSubmit true}}type="submit"{{else}} href="{{.Link}}"{{end}}>
- rickette 2y agoI've given my Go templates a double suffix like index.go.html and index.go.json. Most tools will recognize these as HTML and JSON files so highlighting works as expected. Additionally in JetBrains IDEs you can assign the "GoTemplate" language to .go.html and .go.json files and it will also recognize the template/html and template/text syntax. So this gives you full syntax highlighting of both HTML/JSON and Go templates. See https://github.com/PDOK/gokoala?tab=readme-ov-file#intellij--goland https://github.com/PDOK/gokoala?tab=readme-ov-file#intellij-... for a script to set this up.