go - GoDoc 添加换行符
问题描述
我知道 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:记录 Go 代码
相关部分:
Godoc 在将注释转换为 HTML 时使用了一些格式规则:
- 随后的文本行被视为同一段落的一部分;您必须留一个空行来分隔段落。
- 预先格式化的文本必须相对于周围的注释文本缩进(参见 gob 的 doc.go 示例)。
- URL 将被转换为 HTML 链接;不需要特殊标记。
推荐阅读
- ajax - 如何在 vue3 中不使用 axios 的情况下创建一个通用 api url,该 api url 可用于所有 ajax post 的所有组件并获取请求?
- javascript - 如果没有选择图像的任何部分,如何中止脚本?Photoshop Javascript
- python - 在雪花中存储 SKLearn Birch 模型的有效方法(并绕过 8MB 二进制限制)
- python - 为什么该程序不能在不和谐机器人中用作具有自动角色的验证系统?
- apache-flink - 如何在 FlinkSQL 中按周聚合数据
- amazon-web-services - 无法创建新的 AWS Athena 数据目录
- sql-server - SQL中数据的并排比较
- multithreading - 内核开发 - 如何获取运行特定 cpu 内核的代码?
- qt - 如何从命令行选择 VLC QT 接口配置文件
- python - 在 Keras 中集成多个模型预测触发回溯警告