我想在我的函数注释中包含一些示例代码,如下所示:
// Some example for using `foo`:
//
// ```
// f := Foo(...)
// g := Goo(f)
// ```
func Foo() {
...
}
Run Code Online (Sandbox Code Playgroud)
但是代码块在vscode中没有正确显示。什么是正确的方法呢?
删除那些反引号并缩进代码:
// Foo does ... (note this first line)
// Some example for using Foo:
//
// f := Foo(...)
// g := Goo(f)
func Foo() {
...
}
Run Code Online (Sandbox Code Playgroud)
Godoc 在将注释转换为 HTML 时使用了一些格式规则:
- 后续文本行被视为同一段落的一部分;你必须留一个空行来分隔段落。
- 预先格式化的文本必须相对于周围的注释文本缩进(参见 gob 的 doc.go 示例)。
- URL 将被转换为 HTML 链接;不需要特殊标记。
相关问题: