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: override stdout code block language #61

Open
W1M0R opened this issue Mar 10, 2023 · 2 comments
Open

Feature request: override stdout code block language #61

W1M0R opened this issue Mar 10, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@W1M0R
Copy link

W1M0R commented Mar 10, 2023

I have a code block that looks like this:

{.bash .cb-run show=stdout:verbatim}
my-command-that-produces-json-stdout
EOF

The my-command-that-produces-json-stdout is a command that produces json stdout. This example uses json, but it applies to any other output format.

When the code block stdout is rendered in Pandoc, I want it to be rendered with json syntax highlighting, i.e. as a json code block.

Somehow I would need to inform the codebraid bash code block that a stdout JSON code block should be rendered.

Maybe the rich_format option can be used, e.g. rich_format:json or some other option can be introduced. Ideally, all of the languages that appear in pandoc --list-highlight-languages should be supported.

Another option could be to add a new keyword that is understood by codebraid, e.g. cb-bash-runner, that codebraid will prefer if it exists. If codebraid sees this annotation in the code block header, then it will prefer this as the code runner, and then regular pandoc syntax can be used. The following example indicates that the body of the code block should be rendered as json (something that pandoc does), and that codebraid should execute the body using bash, and then replace the body with the stdout:

{.json .cb-bash-runner .cb-run show=stdout:verbatim}
my-command-that-produces-json-stdout
EOF
@gpoore
Copy link
Owner

gpoore commented Mar 10, 2023

More customization for stdout formatting could be good. The current syntax could probably be extended to support something like show=stdout:verbatim:json or maybe even just show=stdout:json.

Do you anticipate any situations where a single code block will produce stdout in multiple formats? I've been working on new features that could make that possible.

I'm currently finishing the next version of Codebraid Preview, which will bring scroll sync for all Markdown variants, not just commonmark, commonmark_x, and gfm. Once that's done, I will be working on a new version of Codebraid and should be able to incorporate stdout format customization. In the meantime, you could probably try something like show=stdout:raw and then wrap your JSON output like this:

``````{.bash .cb-run show=stdout:raw}
printf "```json\n"
<my-command-that-produces-json-stdout>
printf "```\n"
``````

@gpoore gpoore added the enhancement New feature or request label Mar 10, 2023
@W1M0R
Copy link
Author

W1M0R commented Mar 13, 2023

Thanks for the trick! Using printf '```json\n' (single quotes) worked for me.

I don't anticipate a situation where a single block would produce multiple stdout formats.

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

2 participants