codedown icon indicating copy to clipboard operation
codedown copied to clipboard

Parse/lint each codeblock separately

Open plaindocs opened this issue 5 years ago • 5 comments

Is there a way to easily pass each codeblock to the external parser / linter instead of passing all codeblocks from a file in one go?

plaindocs avatar Jun 17 '20 14:06 plaindocs

Interesting; this sounds useful. Can you describe how you would use it?

earldouglas avatar Jul 09 '21 11:07 earldouglas

I often work with doc sets with multiple code blocks in a single page. There are a few use cases that spring to mind (and I may be slightly rusty with the capabilities of codedown), mostly from a "non-literate" point of view:

  • validating all code samples in a file separately (for example YAML blocks, not interpreted languages)
  • being able to show output from a single code block (this one is harder I think)

plaindocs avatar Jul 11 '21 10:07 plaindocs

What would the interaction with Codedown look like? Are you thinking of using this as a library, or from the command line? If the CLI, would this simply be multiple invocations of codedown with different arguments?

I'm wondering if we can build on the new --section feature here.

earldouglas avatar Dec 28 '23 22:12 earldouglas

I think I'd mostly be using this in CI. If you could add a config section with a commandline to pipe each each code block type to that would do most of the lifting for the first point. A do this for all .py samples and that for all YAML samples?

Possibly with a way to override in the docs with a comment for a specific blog (but that might run into security issues)

Yeah, I see how referencing specific outputs is tricky, unless you can only show the output from the previous blog, but that would also be a good starting point.

I'll go :eyes: the --section feature

plaindocs avatar Jan 17 '24 19:01 plaindocs

You should be achieve this today by invoking Codedown multiple times with different language and section arguments.

If Codedown were to somehow expose the complete parse tree of the document, this could enable some more advanced/programmatic features. This reminds me of jq.

earldouglas avatar Jan 21 '24 19:01 earldouglas