Skip to content

Commit

Permalink
internal/godoc/dochtml: omit "Output" section for examples with no ou…
Browse files Browse the repository at this point in the history
…tput

Fixes golang/go#60986
  • Loading branch information
AlexanderYastrebov committed Jun 28, 2023
1 parent a9d9eed commit e08209d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
26 changes: 26 additions & 0 deletions internal/godoc/dochtml/dochtml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,32 @@ func main() {
0
1
</span></pre>
</div>
<div class="Documentation-exampleButtonsContainer">
<p class="Documentation-exampleError" role="alert" aria-atomic="true"></p>
<button class="Documentation-exampleShareButton" aria-label="Share Code">Share</button>
<button class="Documentation-exampleFormatButton" aria-label="Format Code">Format</button>
<button class="Documentation-exampleRunButton" aria-label="Run Code">Run</button>
</div></details>`,
},
{
name: "Example without output",
htmlID: "example-package-NoOutput",
want: `<details tabindex="-1" id="example-package-NoOutput" class="Documentation-exampleDetails js-exampleContainer">
<summary class="Documentation-exampleDetailsHeader">Example (NoOutput) <a href="#example-package-NoOutput">¶</a></summary>
<div class="Documentation-exampleDetailsBody">
<pre class="Documentation-exampleCode">package main
import (
&#34;fmt&#34;
)
func main() {
fmt.Println(&#34;hello&#34;)
}
</pre>
</div>
<div class="Documentation-exampleButtonsContainer">
<p class="Documentation-exampleError" role="alert" aria-atomic="true"></p>
Expand Down
4 changes: 4 additions & 0 deletions internal/godoc/dochtml/testdata/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,7 @@ func Example_stringsCompare() {
// 0
// 1
}

func Example_noOutput() {
fmt.Println("hello")
}
2 changes: 1 addition & 1 deletion static/doc/example.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<p><a class="Documentation-examplesPlay" href="{{.}}">Open in Go playground »</a></p>{{"\n" -}}
{{- end -}}
{{render_code .Example}}{{"\n" -}}
<pre><span class="Documentation-exampleOutputLabel">Output:</span>{{"\n\n"}}<span class="Documentation-exampleOutput">{{- .Output -}}</span></pre>{{"\n" -}}
{{- if .Output -}}<pre><span class="Documentation-exampleOutputLabel">Output:</span>{{"\n\n"}}<span class="Documentation-exampleOutput">{{- .Output -}}</span></pre>{{"\n" -}}{{- end -}}
</div>{{"\n" -}}
{{- if .Play -}}
<div class="Documentation-exampleButtonsContainer">
Expand Down

0 comments on commit e08209d

Please sign in to comment.