Skip to content

Get head_comment for each document #2185

Answered by mikefarah
krokofant asked this question in Q&A
Discussion options

You must be logged in to vote

Yeah it's definitely faulty, and a known issue. Comment handling is something I've been trying to beat the underlying yaml parser with a stick with - with the way the parser attaches comments to various nodes it's really hard to provide a consistent intuitive behavior for all the various scenarios :(

TLDR I had to do some head pre-processing to fix other header comment parsing issues - but this causes issues in other places, like this. You can turn off the pre-processing and get document 1 to be consistent with document 2 and 3:

yq --header-preprocess=f '.foo | key | head_comment'

Just a word of warning that without the header-preprocessing you can get some issues with block comments at …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by krokofant
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