Re:Show HN: Use Go's HTML/template to write React-like code
by rkwz on Monday May 27, 2024 @10:25AM
(#40491008)
> 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=jinlimin...
Re:Show HN: Use Go's HTML/template to write React-like code
by catlifeonmars on Monday May 27, 2024 @11:29AM
(#40491672)
This is something that should be part of gopls IMO.
Re:Show HN: Use Go's HTML/template to write React-like code
by impune on Monday May 27, 2024 @10:45AM
(#40491216)
In 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.
Re:Show HN: Use Go's HTML/template to write React-like code
by lucideer on Monday May 27, 2024 @12:05PM
(#40492047)
JetBrains "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}}>
Re:Show HN: Use Go's HTML/template to write React-like code
by michaelcampbell on Monday May 27, 2024 @10:51AM
(#40491264)
Thanks for this; JetBrains stuff continues to amaze me. Its blessing and curse is the incredible breadth of functionality I keep learning about.
Re:Show HN: Use Go's HTML/template to write React-like code
by dabber21 on Monday May 27, 2024 @10:41AM
(#40491175)
there are also projects that let you use HTML directly in Go like: https://www.gomponents.com/ (I'm currently using it in a side project and liking it so far, but I also just started)
Re:Show HN: Use Go's HTML/template to write React-like code
by markusw on Monday May 27, 2024 @01:30PM
(#40492831)
Hey, I wrote that! :D I hope you find it useful.
Re:Show HN: Use Go's HTML/template to write React-like code
by rickette on Monday May 27, 2024 @12:52PM
(#40492481)
I'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-... for a script to set this up.
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.