]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/godoc: support m=text parameter for text files
authorAndrew Gerrand <adg@golang.org>
Sun, 13 Jan 2013 22:35:04 +0000 (09:35 +1100)
committerAndrew Gerrand <adg@golang.org>
Sun, 13 Jan 2013 22:35:04 +0000 (09:35 +1100)
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

src/cmd/godoc/godoc.go

index e2d489c5813e67840cc1d7a9688528a311148b00..12148ec1cd4e1ffc74cd70d4f4e0461dcbe1429c 100644 (file)
@@ -15,6 +15,7 @@ import (
        "go/format"
        "go/printer"
        "go/token"
+       htmlpkg "html"
        "io"
        "io/ioutil"
        "log"
@@ -681,10 +682,16 @@ func serveTextFile(w http.ResponseWriter, r *http.Request, abspath, relpath, tit
                return
        }
 
+       if r.FormValue("m") == "text" {
+               serveText(w, src)
+               return
+       }
+
        var buf bytes.Buffer
        buf.WriteString("<pre>")
        FormatText(&buf, src, 1, pathpkg.Ext(abspath) == ".go", r.FormValue("h"), rangeSelection(r.FormValue("s")))
        buf.WriteString("</pre>")
+       fmt.Fprintf(&buf, `<p><a href="/%s?m=text">View as plain text</a></p>`, htmlpkg.EscapeString(relpath))
 
        servePage(w, Page{
                Title:    title + " " + relpath,