Skip to content
Discussion options

You must be logged in to vote

Hi! You can extract the first sh code block using:

mq -A 'filter(fn(n): n | .code.lang == "sh";) | first()' my_file.md
mq -A 'filter(fn(n): n | .code.lang == "sh";)[0]' my_file.md

The -A flag aggregates all nodes into a single array, then filter selects for sh blocks, and first() returns the first one.
However, I feel that the current syntax is a bit cumbersome, so I’m considering ways to make it easier to use in the future.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ruzickap
Comment options

Answer selected by ruzickap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants