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

Add options to control indentation #147

Merged
merged 4 commits into from
Apr 17, 2020
Merged

Add options to control indentation #147

merged 4 commits into from
Apr 17, 2020

Conversation

eemeli
Copy link
Owner

@eemeli eemeli commented Mar 22, 2020

Closes #143
Related: #53

This adds the options indent: number and indentSeq: boolean, to allow for indentation to be customised. The defaults are { indent: 2, indentSeq: true }.

indent is the number of spaces by which each indentation level is prefixed, and should be a positive integer.

If indentSeq is set to false, the '- ' prefix of block sequence items is considered to be a part of the indentation where possible. This requires indent >= 2, and won't apply to sequences with anchors or explicit tags.

const seq = YAML.createNode(['a'])
seq.commentBefore = 'sc'
const map = YAML.createNode({ foo: 'bar', seq })
map.commentBefore = 'mc'
const obj = { array: [{ a: 1, b: 2 }], map }

YAML.stringify(obj, { indent: 1 })
// array:
//  - a: 1
//    b: 2
// map:
//  #mc
//  foo: bar
//  seq:
//   #sc
//   - a

YAML.stringify(obj, { indent: 4, indentSeq: false })
// array:
//   - a: 1
//     b: 2
// map:
//     #mc
//     foo: bar
//     seq:
//         #sc
//       - a

@eemeli eemeli added the enhancement New feature or request label Mar 22, 2020
@eemeli
Copy link
Owner Author

eemeli commented Mar 28, 2020

Rebased to include updates to documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Is there an "Indent Children" Argument for Formatting
1 participant