GoDoc添加换行符 [英] GoDoc add newline character

查看:138
本文介绍了GoDoc添加换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道Golang通过以功能名称(拼写为"func")开头的单行注释来支持功能文档.但是,有一个令人作呕的副作用:具有多个单行注释将不会产生带有换行符的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:

这是函子及其文档:

//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> ,那么一切都会很好)

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

推荐答案

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

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

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

相关部分:

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

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

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

这篇关于GoDoc添加换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆