Source File
comment.go
Belonging Package
go/doc
package doc
import (
// for HTMLEscape
)
const (
ldquo = "“"
rdquo = "”"
ulquo = "“"
urquo = "”"
)
var (
htmlQuoteReplacer = strings.NewReplacer(ulquo, ldquo, urquo, rdquo)
unicodeQuoteReplacer = strings.NewReplacer("``", ulquo, "''", urquo)
)
= convertQuotes()
var bytes.Buffer
htmlQuoteReplacer.WriteString(, .String())
return
}
template.HTMLEscape(, []byte())
}
func ( string) string {
return unicodeQuoteReplacer.Replace()
}
identRx = `[\pL_][\pL_0-9]*`
pathPart = `([.,:;?!]*[a-zA-Z0-9$'()*+&#=@~_/\-\[\]%])*`
urlRx = protoPart + `://` + hostPart + pathPart
)
var matchRx = lazyregexp.New(`(` + urlRx + `)|(` + identRx + `)`)
var (
html_a = []byte(`<a href="`)
html_aq = []byte(`">`)
html_enda = []byte("</a>")
html_i = []byte("<i>")
html_endi = []byte("</i>")
html_p = []byte("<p>\n")
html_endp = []byte("</p>\n")
html_pre = []byte("<pre>")
html_endpre = []byte("</pre>\n")
html_h = []byte(`<h3 id="`)
html_hq = []byte(`">`)
html_endh = []byte("</h3>\n")
)
commentEscape(, [0:[0]], )
= matchRx.FindStringSubmatchIndex([:[0]+len()])
}
}
=
}
= false // don't italicize URLs
}
= [[1]:]
}
commentEscape(, , )
}
func ( string) int {
:= 0
for < len() && ([] == ' ' || [] == '\t') {
++
}
return
}
func ( string) bool {
return len() == 0 || (len() == 1 && [0] == '\n')
}
func (, string) string {
:= 0
for < len() && < len() && [] == [] {
++
}
return [0:]
}
func ( []string) {
if len() == 0 {
return
}
:= [0][0:indentLen([0])]
for , := range {
if !isBlank() {
= commonPrefix(, [0:indentLen()])
}
}
:= len()
for , := range {
if !isBlank() {
[] = [:]
}
}
}
if strings.ContainsAny(, ";:!?+*/=[]{}_^°&§~%#@<\">\\") {
return ""
}
return "hdr-" + nonAlphaNumRx.ReplaceAllString(, "_")
}
func ( io.Writer, string, map[string]string) {
for , := range blocks() {
switch .op {
case opPara:
.Write(html_p)
for , := range .lines {
emphasize(, , , true)
}
.Write(html_endp)
case opHead:
.Write(html_h)
:= ""
for , := range .lines {
if == "" {
= anchorID()
.Write([]byte())
.Write(html_hq)
}
commentEscape(, , true)
}
if == "" {
.Write(html_hq)
}
.Write(html_endh)
case opPre:
.Write(html_pre)
for , := range .lines {
emphasize(, , nil, false)
}
.Write(html_endpre)
}
}
}
func ( string) []block {
var (
[]block
[]string
= false
= false
)
:= func() {
if != nil {
= append(, block{opPara, })
= nil
}
}
:= strings.SplitAfter(, "\n")
unindent()
for := 0; < len(); {
:= []
()
++
= true
continue
}
()
for , := range .lines {
= convertQuotes()
.write()
}
.flush()
case opHead:
.Write(nl)
for , := range .lines {
= convertQuotes()
.write( + "\n")
}
.flush()
case opPre:
.Write(nl)
for , := range .lines {
if isBlank() {
.Write([]byte("\n"))
} else {
.Write([]byte())
.Write([]byte())
}
}
}
}
}
type lineWrapper struct {
out io.Writer
printed bool
width int
indent string
n int
pendSpace int
}
var nl = []byte("\n")
var space = []byte(" ")
var prefix = []byte("// ")
func ( *lineWrapper) ( string) {
if .n == 0 && .printed {
.out.Write(nl) // blank line before new paragraph
}
.printed = true
:= false
:= strings.HasPrefix(, "//")
for , := range strings.Fields() {
if .n > 0 && .n+.pendSpace+ > .width {
.out.Write(nl)
.n = 0
.pendSpace = 0
= && !strings.HasPrefix(, "//")
}
if .n == 0 {
.out.Write([]byte(.indent))
}
if {
.out.Write(prefix)
= false
}
.out.Write(space[:.pendSpace])
.out.Write([]byte())
.n += .pendSpace +
.pendSpace = 1
}
}
func ( *lineWrapper) () {
if .n == 0 {
return
}
.out.Write(nl)
.pendSpace = 0
.n = 0
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |