-
Notifications
You must be signed in to change notification settings - Fork 122
Fix the url in the titles and the files url + support examples generation #20
base: master
Are you sure you want to change the base?
Conversation
Hi, I just refactored my code to:
I also fixed an issue with the current template that adds an empty trailing space at the end of the list of package files. Also, even with the And lastly I updated the examples. You can have a look at what that generates here for example: Let me know what you think. Thanks |
19bfea9
to
108c5f6
Compare
Thanks for doing this. I run some hacky sed commands to fix the URLs when I run godoc2md. I ran into the problem of needing examples today and I didn't see that this PR existed, so I implemented it myself and opened #21. Now, I'm seeing this PR and I'm sorry about the collision. FWIW, I initially implemented it very similarly to you, with an type example struct {
Name string
Doc string
Code string
Output string
}
func examplesFunc(info *godoc.PageInfo, name string) []*example {
//...
} I defined a nested var pkgTemplate = `{{define "examples_md"}}{{range .}}
#### <a name="example_{{.Name}}">Example{{example_suffix .Name}}</a>
{{comment_md .Doc}}
Code:
{{pre .Code}}{{if .Output}}
Output:
{{output .Output}}
{{end}}
{{end}}{{end}}
...
{{range .Funcs}}{{$name_html := html .Name}}### <a name="{{$name_html}}">func</a> [{{$name_html}}]({{posLink_url $ .Decl}})
{{node $ .Decl | pre}}
{{comment_md .Doc}}
{{template "examples_md" (examples $ .Name)}}{{end}}
...
` |
Hi @abursavich , I added the support for printing out the code output in the Anyway, this PR fixes several other issues (I needed a binary with all these fixes anyway), if @davecheney asks me to get rid of all the examples generation I'll do it, no biggy. (but given the other PR sitting here since November without comment I'm not sure he still got time for this project) Joseph |
Closes: #2
Closes: #7
Currently in the title of the functions, methods, types, etc, even in thepackages list, the links are broken.
For example, you get titles like:
What this PR does is that it uses the
URLForSrc
to rewrite the package name into a url using almost the same regex as the gddo project that handles godoc.org.In the end the above title looks like:
And a go package link that used to look like:
Now looks like:
Note that I only added the support for github and bitbucket but I think we can add later on the support for custom package url transformation regex patterns.
I guess it's also related to what was asked in #7 but I'm not 100% sure that what was meant by
link generation is not implemented
.Anyway, let me know what you think about it. Happy to help on improving this.
Thanks
Joseph