cue-lang / cue

The home of the CUE language! Validate and define text-based and dynamic configuration
https://cuelang.org
Apache License 2.0
5.01k stars 285 forks source link

cuelang.org: preprocessor: enable file line numbers inside code blocks #2719

Open jpluscplusm opened 9 months ago

jpluscplusm commented 9 months ago

Is your feature request related to a problem? Please describe.

I'd like to present users of alpha with files that include line numbers, in code blocks created by a {{{with code...}}}.

Currently, it appears that #codetab(file.name) linenos="..." only works in a {{{with upload...}}} context. Or at least that's my experience, backed up by a quick grep of the preprocessor's code:

$ git grep tagCodeTab internal/cmd/preprocessor/cmd/
internal/cmd/preprocessor/cmd/tag.go:   // tagCodeTab identifies the tag key used to pass options to the code-tab emitted
internal/cmd/preprocessor/cmd/tag.go:   // for a file in a txtar-based directive like code or upload. A tagCodeTab
internal/cmd/preprocessor/cmd/tag.go:   tagCodeTab = "codetab"
internal/cmd/preprocessor/cmd/upload_node.go:   opts, _, err := u.tag(tagCodeTab, f.Name)
internal/cmd/preprocessor/cmd/upload_node.go:       return u.errorf("failed to search for tag %v(%v): %v", tagCodeTab, f.Name, err)

Describe the solution you'd like

I'd like to be able to include line numbers in the different styles supported by code blocks when presenting files via the {{{with code...}}} preprocessor mechanism.

Describe alternatives you've considered

I'm currently writing docs that don't refer to line numbers, but instead have inline comments that I refer back to.

Additional context

Discovered whilst working on CL https://review.gerrithub.io/c/cue-lang/cuelang.org/+/1172968.

myitcv commented 4 months ago

@jpluscplusm - can you construct what you need from Hugo primitives (https://cuelang.org/examples/)? i.e. is this just preprocessor shortcomings?

jpluscplusm commented 4 months ago

@jpluscplusm - can you construct what you need from Hugo primitives (https://cuelang.org/examples/)? i.e. is this just preprocessor shortcomings?

Yes, this is just the preprocessor. The example on the code-tabs example page displays a file with line numbers: https://cuelang.org/examples/shortcodes/code-tabs/#usage