what's the proper file extension or abbr. for golang's text/template?

我只是一个虾纸丫 提交于 2019-12-06 16:55:44

问题


I'm thinking about creating syntax highlighter for it, but I don't know the conventional abbreviation for this specific type of template.


回答1:


In one of the examples from the text/template godoc, they refer to ".tmpl" files.




回答2:


If you're using the Atom editor with the go-plus plugin, it provides nice syntax highlighting if you use the .gohtml extension.




回答3:


.ext.tmpl is probably the least bad option based on my analysis of stats from one large codebase that includes quite a bit of Go code.

Proportion of files with one of the extensions (.tpl, .tmpl, .html.tmpl, .html.tpl, .thtml) that contain the pattern /[{][{](-\ )?end/.

.thtml    0%
.gohtml < 1%
.tpl     14%
.tmpl    85%

This misses simpler go templates that do not use loops or conditionals, but not in a way that should skew results.

About a third of the .tmpl files have the form .ext.tmpl of which .html.tmpl is the single most common. A visual inspection of files sampled from within this show that the extension is an accurate description of the output of the file.

Neither the suffix .tpl nor .tmpl is used exclusively for Go templates within this codebase which has a lot of code that predates the Go language. I haven't investigated carefully, but I think it's safe to say that for each of (.tpl, .tmpl), the majority of files with that extension are probably not Go templates.




回答4:


I'm using .html.tmpl. That makes it clear that it's a Go template which will be rendered to HTML. Furthermore, it follows the convention set by other file types like .tar.gz.




回答5:


The html/template package uses .tmpl in their example.
My vote goes to .html.tmpl




回答6:


Since you're writing the highlighter just go with what you normally use. I'm sure the community will give you feedback and eventually some sort of agreement.

As for myself, I'm using .thtml for template html.




回答7:


In VSCode syntax highlighting of templates could be activated for files with extensions:

  • .gohtml or .go.html
  • .gotmpl or .go.tmpl

https://github.com/microsoft/vscode-go/issues/464



来源:https://stackoverflow.com/questions/22254013/whats-the-proper-file-extension-or-abbr-for-golangs-text-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!