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

proposal: x/tools/godoc: add the ability to customize example_text #24862

Closed
aerostitch opened this issue Apr 14, 2018 · 4 comments
Closed

proposal: x/tools/godoc: add the ability to customize example_text #24862

aerostitch opened this issue Apr 14, 2018 · 4 comments

Comments

@aerostitch
Copy link

Version / OS / Processor:

go version go1.10rc2 linux/amd64 (Debian)

Does this issue reproduce with the latest release?

Yes.

What did you do?

While working on a PR for godoc2md I needed to customize the example_text function to make it available as markdown text: davecheney/godoc2md#20
To do that I had to copy/paste quite big chunks of code for very minimal changes.

In fact I had a PR open on tool/godoc to add a new function that would allow people to change the example's title and add text surrounding the example code: golang/tools#33

This would impact any of the existing functionnalities and would allow people to avoid having to create custom code for these kind of usage (can be reused for generating doc in languages like asciidoc, rst, etc).

@gopherbot gopherbot added this to the Proposal milestone Apr 14, 2018
@kevinburke kevinburke changed the title Proposal: tools/godoc - add the ability to customize example_text proposal: tools/godoc: add the ability to customize example_text Apr 14, 2018
@kevinburke kevinburke changed the title proposal: tools/godoc: add the ability to customize example_text proposal: x/tools/godoc: add the ability to customize example_text Apr 14, 2018
@kevinburke
Copy link
Contributor

Looking at the patch: https://github.com/golang/tools/pull/33/files I'm still a little confused about what you're proposing. Do you have screenshots maybe or a URL that contains a concrete example?

@agnivade
Copy link
Contributor

IIUC, you want to import "golang.org/x/tools/godoc" and pass your own input into the example_text function in pres.FuncMap() to generate markdown.

IMO, this is shoe-horning the code base to satisfy a different purpose. If you look at the code change without external context, it is very hard to reason why this is being done, which is for external code to be able to generate markdown.

While I am not against generating markdown, this seems to be the incorrect approach. One should not have to import the godoc package at all to generate markdown. I would expect there to be a button in the package page which can be clicked and a .md file gets downloaded.

@aerostitch
Copy link
Author

aerostitch commented Apr 14, 2018

The idea was to be able to have the example_text2 builtin function that would allow you more flexibility by changing the title and adding delimiters to wrap the code blocks without having to write a customized function.
For example, with golang/tools#33 I could:

  • have a different title than "Example:" on my code block: {{ example_text2 $ .Name "" "Example for .Name" "" "" ""
  • generate the examples in markdown using (with titles to have the links working): {{ example_text2 $ .Name "" "#### Example .Name" "" "``` go" "```"
  • generate the examples in asciidoc format using (with titles to have the links working): {{ example_text2 $ .Name "" "==== Example .Name" "[source,go]\n---" "---"
  • generate the example in restructuredText format using (with titles to have the links working): {{ example_text2 $ .Name " " "==== Example .Name" ".. code:: go" ""

It just sounded dumb to me to have to rewrite a big function when the change I'd need to do in the core library would be really small.
I'm not really a big fan of having to duplicate entire chunks of code from the standard libraries I use just to be able to add 2 lines in it. It seemed more logical to me to propose the changes upstream directly.

The need of godoc is there because what is generated is the go documentation of the package. It's just in another format than the ones currently available.

@rsc
Copy link
Contributor

rsc commented Apr 16, 2018

You can already import go/doc and get a doc.Example and format it however you like. That seems like a clearer path forward than making godoc extensible in a way that it doesn't need. I would expect a godoc2md to use go/doc this way too. Don't do it by rewriting godoc itself.

@rsc rsc closed this as completed Apr 16, 2018
@golang golang locked and limited conversation to collaborators Apr 16, 2019
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

5 participants