Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GoDoc add newline character

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)

like image 346
Mike Warren Avatar asked Aug 01 '18 20:08

Mike Warren


People also ask

How to add a newline character on the console in Python?

To add a newline on the console use the below code– The newline character can be added to print () function in order to display the string on a new line as shown below– print("Hello Folks!

How do I convert comments from godoc to HTML?

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).

What is a newline character in Java?

A newline character, also known as the end of line (EOL), line break or line separator is a control character used to represent the end of a line and the beginning of a new one, separating both of them. In various programming languages including Java, there are multiple ways to add a new line in a string.

What is godoc and how to use it?

For example, through godoc’s web interface you can navigate from a function’s documentation to its implementation with one click. Godoc is conceptually related to Python’s Docstring and Java’s Javadoc but its design is simpler.


Video Answer


1 Answers

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.
like image 158
icza Avatar answered Oct 20 '22 04:10

icza