Open pmwmedia opened 1 year ago
That would be very useful indeed.
Looks like a duplicate of #3230
That other issue has now been closed and locked, but remains very much relevant. We need a way to name template files so that syntax highlighting can know they are Hugo templates.
Any update on this? Tagging @jmooring for visibility.
I would support this as an optional feature, but I don't find it suitable as a new convention.
I think it's fairly common that template files are just named by their intended format. For instance, Django templates are also normally called .html
.
Is there any existing file extension for Go templates, is .gotmpl
a thing?
My worry is that .gohtml
is great for an editor that supports it... but other editors may fail to even do basic .html
highlighting. And in some cases, the user doesn't have real Go Template highlighting, so they have to select HTML and get the same result as when the file was called .html
.
In these cases, use experience is worse. This is also relevant for displaying/previewing code on Git platforms like GitLab, Gitea, Forgejo and their mega-sibling GitHub.
IntelliJ IDEs are smart enough to force a choice with a modal when it doesn't understand the file extension:
But other editors will likely just not syntax highlight at all. Here's gEdit for instance:
The advantage of .gohtml instead of .html is better syntax highlighting for Golang in many IDEs like IntelliJ, without the need for manual hacks.
The template file extension in Hugo is directly connected to the MIME type definition used in layout resolution for a given output format, so any costly special handling of .gohtml
needs stronger arguments.
Prettier with the go-template
do a great job with Go/Hugo templates, and is easy to set up for HTML files. You could restrict this to the layout folder(s) etc.
{
overrides: [
{
files: ["*.html"],
options: {
parser: "go-template",
},
},
],
}
What if we used .go.html
? Then it would default to something useful in the common case, but the extension would be available for keying off of in the case that language extensions wanted to provide more intelligent highlighting/etc.
@nk9 I think in that case, it would be easier to promote a convention for themes to follow. In IntelliJ, wild card patterns define a syntax highlighting, so it's possible to use *.go.html
.
For partials and shortcodes it is already possible with the current version of Hugo to use the file extension
.gohtml
instead of.html
. It would be great if the file extension.gohtml
could also be used for templates.The advantage of
.gohtml
instead of.html
is better syntax highlighting for Golang in many IDEs like IntelliJ, without the need for manual hacks.