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 <adg@golang.org>
This commit is contained in:
parent
c5b51756ce
commit
3d2dab63d9
|
@ -491,8 +491,8 @@ func (p *Presentation) example_htmlFunc(info *PageInfo, funcName string) string
|
||||||
|
|
||||||
err := p.ExampleHTML.Execute(&buf, struct {
|
err := p.ExampleHTML.Execute(&buf, struct {
|
||||||
Name, Doc, Code, Play, Output string
|
Name, Doc, Code, Play, Output string
|
||||||
Share bool
|
Share, Unordered bool
|
||||||
}{eg.Name, eg.Doc, code, play, out, info.Share})
|
}{eg.Name, eg.Doc, code, play, out, info.Share, eg.Unordered})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Print(err)
|
log.Print(err)
|
||||||
}
|
}
|
||||||
|
@ -587,7 +587,7 @@ func startsWithUppercase(s string) bool {
|
||||||
return unicode.IsUpper(r)
|
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
|
// stripExampleSuffix strips lowercase braz in Foo_braz or Foo_Bar_braz from name
|
||||||
// while keeping uppercase Braz in Foo_Braz.
|
// while keeping uppercase Braz in Foo_Braz.
|
||||||
|
|
|
@ -22,7 +22,11 @@
|
||||||
<p>Code:</p>
|
<p>Code:</p>
|
||||||
<pre class="code">{{.Code}}</pre>
|
<pre class="code">{{.Code}}</pre>
|
||||||
{{with .Output}}
|
{{with .Output}}
|
||||||
|
{{if $.Unordered}}
|
||||||
|
<p>Unordered Output:</p>
|
||||||
|
{{else}}
|
||||||
<p>Output:</p>
|
<p>Output:</p>
|
||||||
|
{{end}}
|
||||||
<pre class="output">{{html .}}</pre>
|
<pre class="output">{{html .}}</pre>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
|
@ -450,7 +450,11 @@ var Files = map[string]string{
|
||||||
<p>Code:</p>
|
<p>Code:</p>
|
||||||
<pre class="code">{{.Code}}</pre>
|
<pre class="code">{{.Code}}</pre>
|
||||||
{{with .Output}}
|
{{with .Output}}
|
||||||
|
{{if $.Unordered}}
|
||||||
|
<p>Unordered Output:</p>
|
||||||
|
{{else}}
|
||||||
<p>Output:</p>
|
<p>Output:</p>
|
||||||
|
{{end}}
|
||||||
<pre class="output">{{html .}}</pre>
|
<pre class="output">{{html .}}</pre>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
Loading…
Reference in New Issue