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

x/tools/cmd/godoc: strange HTML whitespace and indentations in source generated #13944

Closed
johanfo opened this issue Jan 13, 2016 · 2 comments

Comments

Projects
None yet
5 participants
@johanfo
Copy link

commented Jan 13, 2016

Take a look at the HTML source of https://golang.org/pkg/fmt/
There are quite some whitespace and strange indentation there, that probably is quite easy to trim.

@johanfo johanfo changed the title Plenty of HTML whitepace in godoc Plenty of HTML whitepace in cmd/godoc Jan 13, 2016

@johanfo johanfo changed the title Plenty of HTML whitepace in cmd/godoc cmd/godoc: Strange HTML whitespace and indentations in source generated Jan 13, 2016

@ianlancetaylor ianlancetaylor changed the title cmd/godoc: Strange HTML whitespace and indentations in source generated cmd/godoc: strange HTML whitespace and indentations in source generated Jan 13, 2016

@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Jan 13, 2016

@minux minux changed the title cmd/godoc: strange HTML whitespace and indentations in source generated x/tools/cmd/godoc: strange HTML whitespace and indentations in source generated Jan 14, 2016

@agnivade

This comment has been minimized.

Copy link
Member

commented Feb 22, 2018

I took a look into this. This has to do with the "text/template" package. Whitespaces in the source code translate to actual whitespace in the html file. Even assignment statements like {{$name := printf "%s_%s" $tname .Name}} create a whitespace in the generated html. It can be somewhat mitigated by using "-" as mentioned here https://golang.org/pkg/text/template/#hdr-Text_and_spaces. But it does not go away completely. And moreover, littering the codebase with "-" does not look good.

I am not fully sure, but I think using the "html/template" package should help in mitigating this naturally.

@andybons

This comment has been minimized.

Copy link
Member

commented Mar 13, 2018

Thanks for the report.

As @agnivade said, the underlying issue here is with the template/* packages, which translates source code whitespace to actual whitespace.

I believe the right path forward would be to propose a change to the template package semantics if you’d like this to change (golang.org/s/proposal) since as of now, this is not a bug, but working as intended.

@andybons andybons closed this Mar 13, 2018

@golang golang locked and limited conversation to collaborators Mar 13, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.