From 3d2dab63d97df38e19a41a8e70432fb905a9b6bc Mon Sep 17 00:00:00 2001 From: Brady Catherman Date: Tue, 8 Mar 2016 22:32:41 -0700 Subject: [PATCH] godoc: Implement Unordered Output. When an Example's output is listed as being Unordered this will make godoc display "Unordered output:" rather than the normal "Output:". For an example of where this is useful, see the recently added example for math.rand.Perm(). Change-Id: I737c901102dca46434f46a48300445bb43ce34e0 Reviewed-on: https://go-review.googlesource.com/20458 Reviewed-by: Andrew Gerrand --- godoc/godoc.go | 6 +++--- godoc/static/example.html | 4 ++++ godoc/static/static.go | 4 ++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/godoc/godoc.go b/godoc/godoc.go index dda1f49c..b2bd42e3 100644 --- a/godoc/godoc.go +++ b/godoc/godoc.go @@ -491,8 +491,8 @@ func (p *Presentation) example_htmlFunc(info *PageInfo, funcName string) string err := p.ExampleHTML.Execute(&buf, struct { Name, Doc, Code, Play, Output string - Share bool - }{eg.Name, eg.Doc, code, play, out, info.Share}) + Share, Unordered bool + }{eg.Name, eg.Doc, code, play, out, info.Share, eg.Unordered}) if err != nil { log.Print(err) } @@ -587,7 +587,7 @@ func startsWithUppercase(s string) bool { return unicode.IsUpper(r) } -var exampleOutputRx = regexp.MustCompile(`(?i)//[[:space:]]*output:`) +var exampleOutputRx = regexp.MustCompile(`(?i)//([[:space:]]*unordered)?[[:space:]]*output:`) // stripExampleSuffix strips lowercase braz in Foo_braz or Foo_Bar_braz from name // while keeping uppercase Braz in Foo_Braz. diff --git a/godoc/static/example.html b/godoc/static/example.html index 3bc0eb9b..aacf4f7e 100644 --- a/godoc/static/example.html +++ b/godoc/static/example.html @@ -22,7 +22,11 @@

Code:

{{.Code}}
{{with .Output}} + {{if $.Unordered}} +

Unordered Output:

+ {{else}}

Output:

+ {{end}}
{{html .}}
{{end}} {{end}} diff --git a/godoc/static/static.go b/godoc/static/static.go index 985243d8..774c7383 100644 --- a/godoc/static/static.go +++ b/godoc/static/static.go @@ -450,7 +450,11 @@ var Files = map[string]string{

Code:

{{.Code}}
{{with .Output}} + {{if $.Unordered}} +

Unordered Output:

+ {{else}}

Output:

+ {{end}}
{{html .}}
{{end}} {{end}}