diff options
| author | Hana Kim <hyangah@gmail.com> | 2026-03-05 21:38:22 -0500 |
|---|---|---|
| committer | Hyang-Ah Hana Kim <hyangah@gmail.com> | 2026-03-12 07:19:18 -0700 |
| commit | 61f82b0145f87d7397ea10c7c8a11ffadba25cb7 (patch) | |
| tree | 69a3f82645c67c1a6f82ce9dae32138e6a108237 /static/doc/example.tmpl | |
| parent | ebeca97f019584573944ae4bf09c50616b5565e7 (diff) | |
| download | go-x-pkgsite-61f82b0145f87d7397ea10c7c8a11ffadba25cb7.tar.xz | |
static: display output container for runnable examples
Examples on pkg.go.dev that are runnable but lack pre-defined output
previously did not display the output container when they were executed.
This was because the template only rendered the output <pre> block
conditionally if .Output was present.
Modified static/doc/example.tmpl to always render the output container
for runnable examples, hiding it by default if no initial output exists.
Updated the PlaygroundExampleController in static/shared/playground/playground.ts
to manage the visibility of this container when execution results are
received.
Added regression tests:
- A client-side unit test in static/shared/playground/playground.test.ts
- A server-side template test in internal/godoc/dochtml/dochtml_test.go
Fixes golang/go#75062
Change-Id: I37b3922c99d956ff1b139834e4625eb8d61b84cd
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/752184
kokoro-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Ethan Lee <ethanalee@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'static/doc/example.tmpl')
| -rw-r--r-- | static/doc/example.tmpl | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/static/doc/example.tmpl b/static/doc/example.tmpl index ab54b246..ece580cf 100644 --- a/static/doc/example.tmpl +++ b/static/doc/example.tmpl @@ -15,7 +15,10 @@ <p><a class="Documentation-examplesPlay" href="{{.}}">Open in Go playground ยป</a></p>{{"\n" -}} {{- end -}} {{render_code .Example}}{{"\n" -}} - {{- if .Output -}}<pre><span class="Documentation-exampleOutputLabel">Output:</span>{{"\n\n"}}<span class="Documentation-exampleOutput">{{- .Output -}}</span></pre>{{"\n" -}}{{- end -}} + {{- if or .Output .Play -}} + <pre class="Documentation-exampleOutputContainer js-exampleOutputContainer" + {{- if not .Output}} hidden{{end}}><span class="Documentation-exampleOutputLabel">Output:</span>{{"\n"}}<span class="Documentation-exampleOutput">{{- .Output -}}</span></pre>{{"\n" -}} + {{- end -}} </div>{{"\n" -}} {{- if .Play -}} <div class="Documentation-exampleButtonsContainer"> |
