Golang go/doc.ToHTML() function example
package go/doc
ToHTML converts comment text to formatted HTML. The comment was prepared by DocReader, so it is known not to have leading, trailing blank lines nor to have trailing spaces at the end of lines. The comment markers have already been removed.
Each span of unindented non-blank lines is converted into a single paragraph. There is one exception to the rule: a span that consists of a single line, is followed by another paragraph span, begins with a capital letter, and contains no punctuation is formatted as a heading.
A span of indented lines is converted into a
<pre>
block, with the common indent prefix removed.URLs in the comment text are converted into links; if the URL also appears in the words map, the link is taken from the map (if the corresponding map value is the empty string, the URL is not converted into a link).
Go identifiers that appear in the words map are italicized; if the corresponding map value is not the empty string, it is considered a URL and the word is converted into a link.
Golang go/doc.ToHTML() function usage example
Example 1:
package main
import (
"fmt"
"go/doc"
"bytes"
)
func main() {
var buf bytes.Buffer
str := "This line must be converted to HTML!"
doc.ToHTML(&buf, str, nil)
fmt.Println(buf.String())
}
Output :
<p>This line must be converted to HTML!</p>
Example 2:
func comment2html(comment string) string {
var buf bytes.Buffer
doc.ToHTML(&buf, comment, nil)
return buf.String()
}
Reference :
Advertisement
Something interesting
Tutorials
+22.7k Golang : Strings to lowercase and uppercase example
+17.2k Google Chrome : Your connection to website is encrypted with obsolete cryptography
+9.9k Golang : Function wrapper that takes arguments and return result example
+20.7k Golang : Read directory content with os.Open
+26.1k Mac/Linux and Golang : Fix bind: address already in use error
+25.3k Golang : Convert uint value to string type
+9.7k Golang : Find correlation coefficient example
+6.5k Golang : Convert an executable file into []byte example
+9k Golang : Inject/embed Javascript before sending out to browser example
+9.6k Golang : How to generate Code 39 barcode?
+17k Golang : Fix cannot convert buffer (type *bytes.Buffer) to type string error
+14.9k Golang : Submit web forms without browser by http.PostForm example