Skip to content

text/template: Comment nodes not show in tree #48150

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
sergiuilie opened this issue Sep 2, 2021 · 2 comments
Closed

text/template: Comment nodes not show in tree #48150

sergiuilie opened this issue Sep 2, 2021 · 2 comments

Comments

@sergiuilie
Copy link

sergiuilie commented Sep 2, 2021

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

$ go version
go version go1.17 windows/amd64

Does this issue reproduce with the latest release?

Yes, this issue is present in go1.17

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

go env Output
$ go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\SIlie\AppData\Local\go-build
set GOENV=C:\Users\SIlie\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\SIlie\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\SIlie\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.17
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\SIlie\AppData\Local\Temp\go-build1192418538=/tmp/go-build -gno-record-gcc-switches

What did you do?

Having a simple comment or a comment with white space trimmed from the preceding and the following text, I am running the template.ParseFiles for my HTML file which contains a comment and I am not able to see the comment node in the tree list, while debugging I observe that the parser doesn't analyze this node at all. It does not matter if the file contains other nodes or not at all, the result is the same.

https://play.golang.org/p/IplCn3fdLf_E

What did you expect to see?

The comment node is present in the tree.

What did you see instead?

Nothing, comment node is not present in the tree.

@seankhliao seankhliao changed the title HTML Template parser does not recognize comment nodes text/template: Comment nodes not show in tree Sep 2, 2021
@seankhliao
Copy link
Member

From https://pkg.go.dev/text/template#Template

The *parse.Tree field is exported only for use by html/template and should be treated as unexported by all other clients.

If you need comments, use text/template/parse and set the Mode

@sergiuilie
Copy link
Author

Great! Thank you for your reply!

@golang golang locked and limited conversation to collaborators Sep 2, 2022
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

3 participants