princjef / gomarkdoc

Generate markdown documentation for Go (golang) code
MIT License
380 stars 60 forks source link

Is there a way to omit certain functions? #109

Open mikeym88 opened 1 year ago

mikeym88 commented 1 year ago

I would like to generate documentation for a package in a project, but I only want to output certain functions (based on our internal naming convention). Is there a way to do designate which functions are included in the doc generation? Or must I use a gotxt template for this?

Would it be possible to get examples of how to do this with and without template files, if possible?

princjef commented 1 year ago

Hi @mikeym88, there is currently no way to exclude functions or types based on their names when invoking the tool. It should be possible, if a bit clunky, to achieve with gotxt files. You would want to use a template override to replace the func and index templates. You can copy them from the default files and modify them to fit your needs. In the func template, you would need an if/else to exclude all output for the functions in question. and in index you'd want to exclude the funcs from the loop that adds them to the index.

With that said, there are still some edge cases around linking, etc. that would be difficult to resolve with pure gotxt templates. It may be reasonable to add an option to exclude certain symbols. If you can give me example of what types of names you want to exclude that might help me determine the feasibility/desired behavior of such a feature

mikeym88 commented 1 year ago

@princjef Thanks for the reply. I ended up figuring out, and I did create custom template files for it.

I created a small utility written in Go that uses gomarkdoc with custom functions added to the templates, namely Contains, HasSuffix, HasPrefix and TrimSpace from the strings package. I was hoping to be able to pass the functions (or at least their names) from the command-line, but that might not be possible?