我知道 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()
}
如何在生成的文档中插入换行符? (如果这是 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/