How to get nice html from godoc?

2,421 views
Skip to first unread message

jake...@gmail.com

unread,
Dec 14, 2017, 1:36:06 PM12/14/17
to golang-nuts
I run godoc like this:

 godoc -html jake\tmp > doc.html

When I open the resulting file (in Chrome or Firefox) the result look terrible. The resulting file is attached. The collapsible sections display as two separate items, are not collapsible, and in Firefox there are strange characters instead of arrows. The preformed text blocks are hard to see, since they contain no special boarder or background and are not indented. The links display all the time as "¶". Etc, etc.

So, how can I easily create and view documentation for my library that looks more like the documentation at https://golang.org/pkg/ ?

Thanks.
doc.html

Justin Israel

unread,
Dec 15, 2017, 5:23:59 PM12/15/17
to jake...@gmail.com, golang-nuts
It's because you are missing the css/js files that godoc pages use. In my studio build system, for the godoc support in our Go plugin, I have it deploying docs with the bundled css/js 

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

jake...@gmail.com

unread,
Dec 16, 2017, 11:48:25 AM12/16/17
to golang-nuts
I suspected it was something like that. I can muddle through, but HTML, and all that is not really my wheelhouse. Can you give me any more details?

  • Where can I find the correct "bundled css/js" files?
  • Where do I put them relative to the HTML file?
  •  Do I need to modify the HTML file to use them?

Thanks

  - Jake

Justin Israel

unread,
Dec 16, 2017, 6:41:07 PM12/16/17
to jake...@gmail.com, golang-nuts
On Sun, Dec 17, 2017 at 5:47 AM <jake...@gmail.com> wrote:
I suspected it was something like that. I can muddle through, but HTML, and all that is not really my wheelhouse. Can you give me any more details?

  • Where can I find the correct "bundled css/js" files?
 
  • Where do I put them relative to the HTML file?
That will be up to you, since you will need to actually format a full-formed html file 
  •  Do I need to modify the HTML file to use them?
Yea. The output from godoc -html is only a snippet. You would need to inspect the source of godoc.org to see an example of what you would need to do:

The css files are responsible for formatting the look of the page.

jake...@gmail.com

unread,
Dec 17, 2017, 3:11:20 PM12/17/17
to golang-nuts
Thanks Justin I will give it a try.

(It certainly would be nice if "godoc -html" could be useful without having to modify the html.)

Justin Israel

unread,
Dec 18, 2017, 3:28:50 PM12/18/17
to jake...@gmail.com, golang-nuts


On Mon, Dec 18, 2017, 9:10 AM <jake...@gmail.com> wrote:
Thanks Justin I will give it a try.

(It certainly would be nice if "godoc -html" could be useful without having to modify the html.)

Seeing as how the godoc command serves the same style as godoc.org, it would be nice if it had flags for generating a full HTML document with inline stylesheets. And/or and option to generate the HTML file along with assets. It would make documentation generating much more simple for arbitrary build and deploy systems. 

Justin Israel

unread,
Dec 18, 2017, 3:45:14 PM12/18/17
to Jake Montgomery, golang-nuts


On Tue, Dec 19, 2017, 9:28 AM Justin Israel <justin...@gmail.com> wrote:


On Mon, Dec 18, 2017, 9:10 AM <jake...@gmail.com> wrote:
Thanks Justin I will give it a try.

(It certainly would be nice if "godoc -html" could be useful without having to modify the html.)

Seeing as how the godoc command serves the same style as godoc.org, it would be nice if it had flags for generating a full HTML document with inline stylesheets. And/or and option to generate the HTML file along with assets. It would make documentation generating much more simple for arbitrary build and deploy systems. 

I just came across this in a quick search:

Never thought of the workaround that was posted; starting the godoc server and wget the generated docs and assets. I really wish this was a builtin flag so that one doesn't have to spin up the server and wait for it to start, generate from an http request, and then shut it down. 
Reply all
Reply to author
Forward
0 new messages