golang的text/template的正确文件扩展名或缩写是什么?

huangapple go评论118阅读模式
英文:

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

问题

我正在考虑为它创建语法高亮器,但我不知道这种特定类型模板的常规缩写是什么。

英文:

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

答案1

得分: 29

text/template godoc的一个示例中,他们提到了".tmpl"文件。

英文:

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

答案2

得分: 21

如果您正在使用Atom编辑器和go-plus插件,它会为您提供漂亮的语法高亮,如果您使用.gohtml扩展名的话。

英文:

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

答案3

得分: 16

.ext.tmpl可能是基于我对一个包含大量Go代码的大型代码库的统计分析的结果中最不糟糕的选项。

具有以下扩展名之一(.tpl、.tmpl、.html.tmpl、.html.tpl、.thtml)的文件中包含模式/[{][{](-\ )?end/的比例。

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

这个统计结果可能会忽略那些不使用循环或条件语句的简单go模板,但不会对结果产生太大影响。

大约三分之一的.tmpl文件的形式为.ext.tmpl,其中.html.tmpl是最常见的一种。从对这些文件的抽样检查来看,扩展名确实准确描述了文件的输出。

在这个代码库中,后缀.tpl.tmpl都不仅仅用于Go模板,因为该代码库中有很多早于Go语言的代码。我没有进行详细的调查,但我认为可以肯定地说,对于(.tpl.tmpl)中的每一个,具有该扩展名的文件中,大多数可能不是Go模板。

英文:

.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

得分: 15

在VSCode中,可以为以下扩展名的文件激活模板的语法高亮显示:

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

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

英文:

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

答案5

得分: 7

我正在使用.html.tmpl。这样可以清楚地表明它是一个将被渲染为HTML的Go模板。此外,它遵循了其他文件类型(如.tar.gz)设定的约定。

英文:

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.

答案6

得分: 2

html/template包在他们的示例中使用.tmpl
我倾向于使用.html.tmpl

英文:

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

答案7

得分: 1

你可以在jetbrains/goland中下载插件:Go Template,它默认使用.gohtml作为文件扩展名。

英文:

In jetbrains/goland, you can download the plugin: Go Template

which use .gohtml as default.

答案8

得分: -1

既然你正在编写高亮显示器,就使用你通常使用的方式吧。我相信社区会给你反馈,并最终达成某种协议。

至于我自己,我使用.thtml作为模板HTML的文件扩展名。

英文:

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.

huangapple
  • 本文由 发表于 2014年3月7日 23:22:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/22254013.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定