Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal/godoc/dochtml: omit "Output" section for examples with no output #68

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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