diff --git a/include/yaml.h b/include/yaml.h index 89050e4f..66164021 100644 --- a/include/yaml.h +++ b/include/yaml.h @@ -1493,7 +1493,6 @@ typedef enum yaml_emitter_state_e { YAML_EMIT_DOCUMENT_CONTENT_STATE, /** Expect DOCUMENT-END. */ YAML_EMIT_DOCUMENT_END_STATE, - /** Expect the first item of a flow sequence. */ YAML_EMIT_FLOW_SEQUENCE_FIRST_ITEM_STATE, /** Expect an item of a flow sequence. */ @@ -1626,6 +1625,8 @@ typedef struct yaml_emitter_s { int canonical; /** The number of indentation spaces. */ int best_indent; + /** Whether or not to indent block sequences in mapping context. */ + int indent_mapping_sequence; /** The preferred width of the output lines. */ int best_width; /** Allow unescaped non-ASCII characters? */ @@ -1874,6 +1875,16 @@ yaml_emitter_set_canonical(yaml_emitter_t *emitter, int canonical); YAML_DECLARE(void) yaml_emitter_set_indent(yaml_emitter_t *emitter, int indent); +/* + * Set whether or not to indent block sequences in mapping context. + * + * @param[in,out] emitter An emitter object. + * @param[in] indent_mapping_sequence Boolean. + */ + +YAML_DECLARE(void) +yaml_emitter_set_indent_mapping_sequence(yaml_emitter_t *emitter, int indent_mapping_sequence); + /** * Set the preferred line width. @c -1 means unlimited. * diff --git a/src/api.c b/src/api.c index 16f88bd7..8fc71a3a 100644 --- a/src/api.c +++ b/src/api.c @@ -540,6 +540,18 @@ yaml_emitter_set_indent(yaml_emitter_t *emitter, int indent) emitter->best_indent = (1 < indent && indent < 10) ? indent : 2; } +/* + * Set whether or not to indent block sequences in mapping context. + */ + +YAML_DECLARE(void) +yaml_emitter_set_indent_mapping_sequence(yaml_emitter_t *emitter, int indent_mapping_sequence) +{ + assert(emitter && "Non-NULL emitter object expected."); + + emitter->indent_mapping_sequence = indent_mapping_sequence; +} + /* * Set the preferred line width. */ diff --git a/src/emitter.c b/src/emitter.c index 609b28a4..ec06830e 100644 --- a/src/emitter.c +++ b/src/emitter.c @@ -886,7 +886,9 @@ yaml_emitter_emit_block_sequence_item(yaml_emitter_t *emitter, if (first) { if (!yaml_emitter_increase_indent(emitter, 0, - (emitter->mapping_context && !emitter->indention))) + (emitter->mapping_context + && !emitter->indent_mapping_sequence + && !emitter->indention))) return 0; }