GoDoc 添加换行符

标签 go documentation godoc

我知道 Golang 支持通过以函数名称(拼写为“func”)开头的单行注释来记录函数。然而,有一个令人作呕的副作用:有多个单行注释不会产生一个用换行符分隔每行文本的 GoDoc

这里有一张图片来说明:

enter image description here

这是函数及其文档:

//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()
}

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

最佳答案

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

// 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()
}

推荐博文:Godoc: documenting Go code

相关部分:

There are a few formatting rules that Godoc uses when converting comments to HTML:

  • Subsequent lines of text are considered part of the same paragraph; you must leave a blank line to separate paragraphs.
  • Pre-formatted text must be indented relative to the surrounding comment text (see gob's doc.go for an example).
  • URLs will be converted to HTML links; no special markup is necessary.

关于GoDoc 添加换行符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51641640/

相关文章:

pointers - reflect如何获取返回的结构体指针

go - 如何将错误消息从 C 传递给 Go?

MySQL 8.0 Reference 说 MOD() + 1 返回与 1 + MOD() 不同的结果

go - 运行 "go doc"导致 "no such tool"错误

go - 在 golang 中将结构上的方法作为回调传递

c - 在现有 C 项目中使用 Go 代码

documentation - 从 Tornado Web 服务器代码生成交互式 API 文档

php - 使用 PHPDoc 显示多行 @param 的正确方法是什么?

go - godoc 无法为内部文件夹中的包创建文档吗?

go - godoc本身的源代码在哪里?