From a24b1495877ce0f3bb1afa4815a4be3c83e298d0 Mon Sep 17 00:00:00 2001 From: tdakkota Date: Mon, 24 Apr 2023 08:59:51 +0300 Subject: [PATCH] fix: put indentation before tag of block mapping --- emitterc.go | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/emitterc.go b/emitterc.go index 208621e..d3cefe6 100644 --- a/emitterc.go +++ b/emitterc.go @@ -766,11 +766,6 @@ func yaml_emitter_emit_block_sequence_item(emitter *yaml_emitter_t, event *yaml_ // Expect a block key node. func yaml_emitter_emit_block_mapping_key(emitter *yaml_emitter_t, event *yaml_event_t, first bool) bool { - if first { - if !yaml_emitter_increase_indent(emitter, false, false) { - return false - } - } if !yaml_emitter_process_head_comment(emitter) { return false } @@ -932,16 +927,38 @@ func yaml_emitter_emit_sequence_start(emitter *yaml_emitter_t, event *yaml_event // Expect MAPPING-START. func yaml_emitter_emit_mapping_start(emitter *yaml_emitter_t, event *yaml_event_t) bool { - if !yaml_emitter_process_anchor(emitter) { - return false - } - if !yaml_emitter_process_tag(emitter) { - return false - } if emitter.flow_level > 0 || emitter.canonical || event.mapping_style() == yaml_FLOW_MAPPING_STYLE || yaml_emitter_check_empty_mapping(emitter) { + if !yaml_emitter_process_anchor(emitter) { + return false + } + if !yaml_emitter_process_tag(emitter) { + return false + } emitter.state = yaml_EMIT_FLOW_MAPPING_FIRST_KEY_STATE } else { + // FIXME(tdakkota): should we do it for sequence/flow style? + // + // Write same indent as mapping have. + // In cases like this: + // + // a: + // b: # comment + // !tag + // c: + // + if !yaml_emitter_increase_indent(emitter, false, false) { + return false + } + if !yaml_emitter_write_indent(emitter) { + return false + } + if !yaml_emitter_process_anchor(emitter) { + return false + } + if !yaml_emitter_process_tag(emitter) { + return false + } emitter.state = yaml_EMIT_BLOCK_MAPPING_FIRST_KEY_STATE } return true