Skip to content

Commit

Permalink
fix: put indentation before tag of block mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
tdakkota committed Apr 24, 2023
1 parent ac9ecfe commit a24b149
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions emitterc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a24b149

Please sign in to comment.