doucheng1884 2018-08-01 20:17
浏览 167
已采纳

GoDoc添加换行符

I know that Golang supports documentation of functions via single-line comments starting with the name of the function (spelled "func"). However, there's a nauseating side effect: having multiple single line comments will not produce a GoDoc with newline characters separating each line of text

Here's a pic to illustrate:

enter image description here

Here's the func, and its documentation:

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

How does one insert newlines in the generated documentation? (If this were Javadoc, I would be like <br> and all would be good)

  • 写回答

1条回答 默认 最新

  • douji7399 2018-08-01 20:24
    关注

    Insert an empty comment line, and it will be a new paragraph, meaning it will start on a new line:

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

    Recommended blog post: Godoc: documenting Go code

    Relevant section:

    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.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效