Commit 2b3fd370 authored by Johan Euphrosine's avatar Johan Euphrosine Committed by Robert Griesemer

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
parent cf0cbfd2
......@@ -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("<pre><!--{{%s}}\n-->%s</pre>", command, text)
text = fmt.Sprintf("<pre><!--{{%s}}\n-->%s</pre>", command, buf.Bytes())
return text, nil
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment