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

Feature request: Allow overriding base header levels for embedded #62

Open
shakefu opened this issue Jan 27, 2022 · 3 comments
Open

Feature request: Allow overriding base header levels for embedded #62

shakefu opened this issue Jan 27, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@shakefu
Copy link

shakefu commented Jan 27, 2022

Use case:

We have a markdown README like:

# My Project

Blah blah blah blah

## API Documentation

<!-- gomarkdoc:embed -->

... and would like for either the CLI, or preferably the embed comment itself to allow for overriding the .Level of the headers inserted within.

Bonus feature request: Allow for skipping the {{- header .Level .Name -}} and {{- codeBlock "go" .Import -}} sections of the package template since they're a bit redundant in that context.

Proposal

Ideally, some kind of context to the tagging (it gets parsed with a regex, I've seen), e.g.:

<!-- gomarkdown:embed:--no-header,--no-import,--level=3 -->

... with parity in the CLI:

gomarkdoc --verbose --output '{{ .Dir }}/README.md' --embed --embed-no-header --embed-no-import --embed-level=3 ./...
@princjef
Copy link
Owner

princjef commented Jul 7, 2022

This is an interesting suggestion. The ability to customize the level feels particularly useful for embedding scenarios, especially since the levels are mostly hardcoded right now and would have to be changed in multiple places.

A couple questions:

  • Do you need the ability to use different levels for each embed or is a CLI parameter sufficient if it applies the same to all levels?
  • Any reason not to simply omit the header and import by customizing the template(s)? I can potentially split the header into its own template like the import is now, but the behavior you're asking for feels more appropriate for the template than as a bespoke parameter. If you want to run embedded and non-embedded scenarios through the same configuration, the tool could provide some sort of isEmbedded function so you can vary the behavior

@shakefu
Copy link
Author

shakefu commented Jul 8, 2022

  • Do you need the ability to use different levels for each embed or is a CLI parameter sufficient if it applies the same to all levels?

My primary use case is embedding in the repo root readme, so really only one level is sufficient. Including the docs in pkg/blah/ readmes would probably warrant multiple levels if they were rendered out simultaneously.

  • Any reason not to simply omit the header and import by customizing the template(s)? I can potentially split the header into its own template like the import is now, but the behavior you're asking for feels more appropriate for the template than as a bespoke parameter. If you want to run embedded and non-embedded scenarios through the same configuration, the tool could provide some sort of isEmbedded function so you can vary the behavior

I think I looked at this and decided it wouldn't be trivial, but it's been long enough that I don't recall. Our use case is targeting a pre-commit hook to ensure the docs are always up to date in the codebase across many Go repos, so we were hoping for a standard/cli solution that didn't involve external resources, e.g. a customized template.

@princjef princjef added the enhancement New feature or request label Jun 12, 2023
@nikolaik
Copy link

nikolaik commented Jan 12, 2024

Super interested in this!

For inspiration there is a similar CLI parameter in the terraform-docs project which also can generate markdown (based on terraform code) and allows embedding into other markdown files. They call it injecting instead of embedding and the parameter is called indent instead of the suggested embed-level.

An example, which adds a reference section in your hand written README:

README.md:

# My module

Some hand written prose

## Reference

<!-- BEGIN_TF_DOCS -->

<!-- END_TF_DOCS -->

Then you can run

$ terraform-docs markdown . --output-file README.md --indent 3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants