Skip to content

Commit

Permalink
Also indent top-level scalars with lines starting with % directives (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
eemeli committed May 9, 2020
1 parent 0426e4a commit 3900895
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/stringify/stringifyString.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ const getFoldOptions = ({ indentAtStart }) =>
? Object.assign({ indentAtStart }, strOptions.fold)
: strOptions.fold

const containsDocumentMarker = str => /^(---|\.\.\.)/m.test(str)
// Also checks for lines starting with %, as parsing the output as YAML 1.1 will
// presume that's starting a new document.
const containsDocumentMarker = str => /^(%|---|\.\.\.)/m.test(str)

function lineLengthOverLimit(str, limit) {
const strLen = str.length
Expand Down
6 changes: 6 additions & 0 deletions tests/doc/stringify.js
Original file line number Diff line number Diff line change
Expand Up @@ -671,4 +671,10 @@ describe('Document markers in top-level scalars', () => {
expect(str).toBe('"foo\n\n ..."\n')
expect(YAML.parse(str)).toBe('foo\n...')
})

test('foo\\n%bar\\n', () => {
const str = YAML.stringify('foo\n%bar\n')
expect(str).toBe('|\n foo\n %bar\n')
expect(YAML.parse(str)).toBe('foo\n%bar\n')
})
})

0 comments on commit 3900895

Please sign in to comment.