libyaml icon indicating copy to clipboard operation
libyaml copied to clipboard

Indentation of sequence elements

Open galdor opened this issue 2 years ago • 5 comments

In the current version (0.2.5) the emitter does not indent sequence elements for the block sequence style, e.g.:

foo:
- hello
- world

While correct, it is way harder to read than the more conventional representation where sequence elements are indented:

foo:
  - hello
  - world

This is quite noticeable in large documents with lots of deeply nested values.

Would it be possible to add an option to support this kind of output ?

Looking at the repository, I am not sure who is in charge of coordinating development for libyaml, so any pointer is welcome :) I may be able to provide a patch if someone can provide a minimum of guidance and is ok with merging it and releasing a new version.

A lot of libraries in various languages rely on libyaml, this would help lots of people !

galdor avatar Sep 10 '21 17:09 galdor

foo:
- hello
- world

I actually prefer this representation and use it across all YAML files I write manually.

i-ky avatar Sep 10 '21 19:09 i-ky

Anyone ? Is libyaml even maintained ?

galdor avatar Sep 22 '21 07:09 galdor

@galdor I too would really appreciate the ability to be able to output sequences with this style of indentation. Perhaps @perlpunk @ingydotnet could advise on a way to proceed and provide code review/merging/version bump when appropriate

samrjenkins avatar Nov 28 '21 16:11 samrjenkins

I'd like this feature to be implemented, too. I can think of three different ways we might want to do that:

  1. Simply indent sequences by the user-configured indent, i.e. set by yaml_emitter_set_indent.
  2. Add a flag to the aforementioned function to enable/disable sequence indentation, e.g, something like: yaml_emitter_set_indent(yaml_emitter_t* emitter, int indent, int indent_block_sequences).
  3. Maybe add a flag to the function yaml_sequence_start_event_initialize(), like above?

Any maintainer input here? I understand this is probably a lower priority item than some other issues.

AmateurECE avatar Feb 05 '22 05:02 AmateurECE

I agree that many huge yaml files with nested values would be easy to read if the emitter produce sequences with indentation.

ziyangc97 avatar Aug 21 '22 08:08 ziyangc97