From cd64704ad6475267929b31d8f941da7e2c0c6a88 Mon Sep 17 00:00:00 2001 From: Alexander Yastrebov Date: Wed, 28 Jun 2023 22:49:32 +0200 Subject: [PATCH] internal/godoc/dochtml: omit "Output" section for examples with no output Fixes golang/go#60986 --- internal/godoc/dochtml/dochtml_test.go | 26 +++++++++++++++++++ .../godoc/dochtml/testdata/example_test.go | 4 +++ static/doc/example.tmpl | 2 +- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/internal/godoc/dochtml/dochtml_test.go b/internal/godoc/dochtml/dochtml_test.go index 9b443b418..271142caa 100644 --- a/internal/godoc/dochtml/dochtml_test.go +++ b/internal/godoc/dochtml/dochtml_test.go @@ -178,6 +178,32 @@ func main() { 0 1 + +
+ + + + +
`, + }, + { + name: "Example without output", + htmlID: "example-package-NoOutput", + want: `
+Example (NoOutput) +
+ +
package main
+
+import (
+	"fmt"
+)
+
+func main() {
+	fmt.Println("hello")
+}
+
+
diff --git a/internal/godoc/dochtml/testdata/example_test.go b/internal/godoc/dochtml/testdata/example_test.go index 83b615e1c..c4249b1a8 100644 --- a/internal/godoc/dochtml/testdata/example_test.go +++ b/internal/godoc/dochtml/testdata/example_test.go @@ -46,3 +46,7 @@ func Example_stringsCompare() { // 0 // 1 } + +func Example_noOutput() { + fmt.Println("hello") +} diff --git a/static/doc/example.tmpl b/static/doc/example.tmpl index 8044c0c3d..b5d7e2349 100644 --- a/static/doc/example.tmpl +++ b/static/doc/example.tmpl @@ -15,7 +15,7 @@

Open in Go playground »

{{"\n" -}} {{- end -}} {{render_code .Example}}{{"\n" -}} -
Output:{{"\n\n"}}{{- .Output -}}
{{"\n" -}} + {{- if .Output -}}
Output:{{"\n\n"}}{{- .Output -}}
{{"\n" -}}{{- end -}}
{{"\n" -}} {{- if .Play -}}