Skip to content

affected/package: godoc have problems with code blocks insode Example* fucntions #59383

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

Closed
kazhuravlev opened this issue Apr 2, 2023 · 4 comments

Comments

@kazhuravlev
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.20.2 darwin/arm64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/zhuravlev/Library/Caches/go-build"
GOENV="/Users/zhuravlev/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/zhuravlev/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/zhuravlev/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/homebrew/Cellar/go/1.20.2/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/homebrew/Cellar/go/1.20.2/libexec/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.20.2"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/nn/ypz91trn6y1cq6v4r_6h7kl00000gn/T/go-build434686067=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

  1. Create a function and example for it
  2. Define a code block inside of example function
  3. Run godoc -http localhost:6060 and scroll to example
  4. You can see a syntax error in this example

Fastest way to see the problem

  1. See source of simple example and result HTML
  2. See source of advanced example and result HTML

Fastest way to reproduce (localy)

git clone [email protected]:kazhuravlev/example-godoc-problem.git
cd example-godoc-problem
godoc -http localhost:6060
open http://localhost:6060/pkg/github.com/kazhuravlev/example-godoc-problem/example1/#example_Add
open http://localhost:6060/pkg/github.com/kazhuravlev/example-godoc-problem/example2/#example_Add

Minimal example:

Create a function

// math.go
package math

func Add(a, b int) int { return a + b }

... and example for it. Example MUST contains a code block inside.

// math_test.go
package math

import "fmt"

func ExampleAdd() {
	{
		fmt.Println(Add(1, 2))
		// Output: 3
	}
}

Here is resulting html (note that last bracket is not presented in result):

{
    fmt.Println(Add(1, 2))
    

Extended example:

Extend your example function by adding a one more code block after first one. Like this:

// math_test.go
package math

import (
	"fmt"
)

func ExampleAdd() {
	{
		fmt.Println(Add(1, 2))
		// Output: 3
	}

	{
		_ = Add(1, 2)
	}
}

... and generate HTML again. You will not see a second code block in resulted HTML.

What did you expect to see?

I am expect, that all code inside Example* function will be presented in result HTML. In case that this is a feature (hiding unnecessary code) - I am expect that at least first code block will be fully rendered in result HTML.

What did you see instead?

I see not valid (syntactically) code in rendered HTML.

@seankhliao
Copy link
Member

see #59056 , we'll no longer be working on x/tools/cmd/godoc

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Apr 2, 2023
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/483297 mentions this issue: godoc: fix example output removal inside code blocks

@aarzilli
Copy link
Contributor

aarzilli commented Apr 9, 2023

I think this issue should be reopened, firstly because godoc fate hasn't been officially decided yet, secondly because it also affects x/pkgsite.

@kazhuravlev
Copy link
Author

Thanks for supporting)
Anyway - if that issue is not related to golang/go repo - please suggest where is the right place for that.

@golang golang locked and limited conversation to collaborators Apr 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants