Skip to content

Custom tags are printed on newline instead of after the key #399

@avisprince

Description

@avisprince

Describe the bug
I am creating custom tags that handles non scalar values. The way the yaml is formatted though is unexpected. See below:

Expected:

foo:
  bar: !append
    - hello
    - world

Actual

foo:
  bar:
    !append
    - hello
    - world

To Reproduce
Here is my code:

const APPEND_PATCH = {
  tag: '!append',  
  identify: value => value.tag === '!append',
  createNode: (_, item) => {
    const x = new yaml.YAMLSeq();
    x.tag = '!append';
    item.value.forEach(v => x.add(v));
    return x;
  },
}

class AppendPatch {
  tag = '!append';
  value;

  constructor(val) {
    this.value = val;
  }
}

const TEST = {
  foo: {
    bar: new AppendPatch(['hello', 'world'])
  }
}

const result = yaml.stringify(struct, {
    nullStr: '~',
    customTags: [APPEND_PATCH],
  });

console.log(result);

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions