@@ -266,7 +266,7 @@ function plainString(
266266 onChompKeep ?: ( ) => void
267267) {
268268 const { type, value } = item
269- const { actualString, implicitKey, indent, inFlow } = ctx
269+ const { actualString, implicitKey, indent, indentStep , inFlow } = ctx
270270 if (
271271 ( implicitKey && / [ \n [ \] { } , ] / . test ( value ) ) ||
272272 ( inFlow && / [ [ \] { } , ] / . test ( value ) )
@@ -298,9 +298,13 @@ function plainString(
298298 // Where allowed & type not set explicitly, prefer block style for multiline strings
299299 return blockString ( item , ctx , onComment , onChompKeep )
300300 }
301- if ( indent === '' && containsDocumentMarker ( value ) ) {
302- ctx . forceBlockIndent = true
303- return blockString ( item , ctx , onComment , onChompKeep )
301+ if ( containsDocumentMarker ( value ) ) {
302+ if ( indent === '' ) {
303+ ctx . forceBlockIndent = true
304+ return blockString ( item , ctx , onComment , onChompKeep )
305+ } else if ( implicitKey && indent === indentStep ) {
306+ return quotedString ( value , ctx )
307+ }
304308 }
305309 const str = value . replace ( / \n + / g, `$&\n${ indent } ` )
306310 // Verify that output will be parsed as a string, as e.g. plain numbers and
0 commit comments