Commit be259647 authored by Andrew Gerrand's avatar Andrew Gerrand

cmd/godoc: support m=text parameter for text files

It's possible to view the package docs in plain text, eg:
        http://golang.org/pkg/time/?m=text
and this CL introduces the ability to do the same for files:
        http://golang.org/src/pkg/time/time.go?m=text

R=golang-dev, dave, minux.ma
CC=golang-dev
https://golang.org/cl/7085054
parent 94878070
...@@ -15,6 +15,7 @@ import ( ...@@ -15,6 +15,7 @@ import (
"go/format" "go/format"
"go/printer" "go/printer"
"go/token" "go/token"
htmlpkg "html"
"io" "io"
"io/ioutil" "io/ioutil"
"log" "log"
...@@ -681,10 +682,16 @@ func serveTextFile(w http.ResponseWriter, r *http.Request, abspath, relpath, tit ...@@ -681,10 +682,16 @@ func serveTextFile(w http.ResponseWriter, r *http.Request, abspath, relpath, tit
return return
} }
if r.FormValue("m") == "text" {
serveText(w, src)
return
}
var buf bytes.Buffer var buf bytes.Buffer
buf.WriteString("<pre>") buf.WriteString("<pre>")
FormatText(&buf, src, 1, pathpkg.Ext(abspath) == ".go", r.FormValue("h"), rangeSelection(r.FormValue("s"))) FormatText(&buf, src, 1, pathpkg.Ext(abspath) == ".go", r.FormValue("h"), rangeSelection(r.FormValue("s")))
buf.WriteString("</pre>") buf.WriteString("</pre>")
fmt.Fprintf(&buf, `<p><a href="/%s?m=text">View as plain text</a></p>`, htmlpkg.EscapeString(relpath))
servePage(w, Page{ servePage(w, Page{
Title: title + " " + relpath, Title: title + " " + relpath,
......
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