GoDoc添加换行符

Mik*_*ren 2 documentation go godoc

我知道Golang通过以功能名称(拼写为“ func”)开头的单行注释来支持功能文档。但是,这有一个令人作呕的副作用:具有多个单行注释将不会生成带有换行符的GoDoc,该换行符将文本的每一行分开

这是一张图片来说明:

在此处输入图片说明

这是函子及其文档:

//GetFunctionName gets function name
// Parameters:
// - `i` : Function
// **NOTE** this func fails if `i` is a variable set to a func
// (they're called "anonymous functions" in JavaScript)
func GetFunctionName(i interface{}) string {
    return runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name()
}
Run Code Online (Sandbox Code Playgroud)

如何在生成的文档中插入换行符?(如果这是Javadoc,我希望<br>一切都会很好)

icz*_*cza 6

插入一个空的注释行,它将是一个新段落,这意味着它将以新行开始:

// GetFunctionName gets function name
//
// Parameters:
//   - `i` : Function
//
// **NOTE** this func fails if `i` is a variable set to a func
// (they're called "anonymous functions" in JavaScript)
func GetFunctionName(i interface{}) string {
    return runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name()
}
Run Code Online (Sandbox Code Playgroud)

推荐的博客文章:Godoc:记录Go代码

相关部分:

Godoc在将注释转换为HTML时使用一些格式化规则:

  • 随后的文本行被视为同一段落的一部分;您必须留空行以分隔段落。
  • 预先格式化的文本必须相对于周围的注释文本缩进(有关示例,请参阅gob的doc.go)。
  • 网址将转换为HTML链接;无需特殊标记。