mirror of
https://github.com/golang/go
synced 2024-11-25 01:27:56 -07:00
godoc: use FormatText for formating code in html template.
R=golang-dev, rsc, r, adg, gri, r CC=golang-dev https://golang.org/cl/5835046
This commit is contained in:
parent
cf0cbfd21a
commit
2b3fd37066
@ -32,6 +32,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"regexp"
|
"regexp"
|
||||||
@ -98,10 +99,11 @@ func code(file string, arg ...interface{}) (s string, err error) {
|
|||||||
text = strings.Trim(text, "\n")
|
text = strings.Trim(text, "\n")
|
||||||
// Replace tabs by spaces, which work better in HTML.
|
// Replace tabs by spaces, which work better in HTML.
|
||||||
text = strings.Replace(text, "\t", " ", -1)
|
text = strings.Replace(text, "\t", " ", -1)
|
||||||
// Escape the program text for HTML.
|
var buf bytes.Buffer
|
||||||
text = template.HTMLEscapeString(text)
|
// HTML-escape text and syntax-color comments like elsewhere.
|
||||||
|
FormatText(&buf, []byte(text), -1, true, "", nil)
|
||||||
// Include the command as a comment.
|
// Include the command as a comment.
|
||||||
text = fmt.Sprintf("<pre><!--{{%s}}\n-->%s</pre>", command, text)
|
text = fmt.Sprintf("<pre><!--{{%s}}\n-->%s</pre>", command, buf.Bytes())
|
||||||
return text, nil
|
return text, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user