Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Control Indent Mapping Context #241

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion include/yaml.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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? */
Expand Down Expand Up @@ -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.
*
Expand Down
12 changes: 12 additions & 0 deletions src/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
4 changes: 3 additions & 1 deletion src/emitter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down