From: Johan Euphrosine Date: Fri, 16 Mar 2012 22:33:05 +0000 (-0700) Subject: godoc: use FormatText for formating code in html template. X-Git-Tag: weekly.2012-03-22~56 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=2b3fd37066694374d6ea6c6c6f2df8cad08410eb;p=gostls13.git 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 --- diff --git a/src/cmd/godoc/template.go b/src/cmd/godoc/template.go index 51b63a804f..d709baef49 100644 --- a/src/cmd/godoc/template.go +++ b/src/cmd/godoc/template.go @@ -32,6 +32,7 @@ package main import ( + "bytes" "fmt" "log" "regexp" @@ -98,10 +99,11 @@ func code(file string, arg ...interface{}) (s string, err error) { text = strings.Trim(text, "\n") // Replace tabs by spaces, which work better in HTML. text = strings.Replace(text, "\t", " ", -1) - // Escape the program text for HTML. - text = template.HTMLEscapeString(text) + var buf bytes.Buffer + // HTML-escape text and syntax-color comments like elsewhere. + FormatText(&buf, []byte(text), -1, true, "", nil) // Include the command as a comment. - text = fmt.Sprintf("
%s
", command, text) + text = fmt.Sprintf("
%s
", command, buf.Bytes()) return text, nil }