【问题标题】:GoDoc add newline characterGoDoc 添加换行符
【发布时间】:2019-01-09 12:26:12
【问题描述】:

我知道 Golang 支持通过以函数名称(拼写为“func”)开头的单行 cmets 来记录函数。但是,有一个令人作呕的副作用:拥有多个单行 cmets 不会生成带有换行符分隔每行文本的 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>,一切都会好起来的)

【问题讨论】:

    标签: go documentation godoc


    【解决方案1】:

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

    // 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

    相关部分:

    Godoc 在将 cmets 转换为 HTML 时使用了一些格式规则:

    • 随后的文本行被视为同一段落的一部分;您必须留一个空行来分隔段落。
    • 预格式化文本必须相对于周围的注释文本缩进(参见 gob 的 doc.go 示例)。
    • URL 将被转换为 HTML 链接;不需要特殊标记。

    【讨论】:

      猜你喜欢
      • 2017-02-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多