@@ -246,29 +246,37 @@ function blockString(
246
246
}
247
247
248
248
const indentSize = indent ? '2' : '1' // root is at -1
249
- let header =
250
- ( literal ? '|' : '>' ) + ( startWithSpace ? indentSize : '' ) + chomp
249
+ // Leading | or > is added later
250
+ let header = ( startWithSpace ? indentSize : '' ) + chomp
251
251
if ( comment ) {
252
252
header += ' ' + commentString ( comment . replace ( / ? [ \r \n ] + / g, ' ' ) )
253
253
if ( onComment ) onComment ( )
254
254
}
255
255
256
- if ( literal ) {
257
- value = value . replace ( / \n + / g, `$&${ indent } ` )
258
- return `${ header } \n${ indent } ${ start } ${ value } ${ end } `
256
+ if ( ! literal ) {
257
+ const foldedValue = value
258
+ . replace ( / \n + / g, '\n$&' )
259
+ . replace ( / (?: ^ | \n ) ( [ \t ] .* ) (?: ( [ \n \t ] * ) \n (? ! [ \n \t ] ) ) ? / g, '$1$2' ) // more-indented lines aren't folded
260
+ // ^ more-ind. ^ empty ^ capture next empty lines only at end of indent
261
+ . replace ( / \n + / g, `$&${ indent } ` )
262
+ let literalFallback = false
263
+ const foldOptions = getFoldOptions ( ctx , true )
264
+ if ( blockQuote !== 'folded' && type !== Scalar . BLOCK_FOLDED ) {
265
+ foldOptions . onOverflow = ( ) => {
266
+ literalFallback = true
267
+ }
268
+ }
269
+ const body = foldFlowLines (
270
+ `${ start } ${ foldedValue } ${ end } ` ,
271
+ indent ,
272
+ FOLD_BLOCK ,
273
+ foldOptions
274
+ )
275
+ if ( ! literalFallback ) return `>${ header } \n${ indent } ${ body } `
259
276
}
260
- value = value
261
- . replace ( / \n + / g, '\n$&' )
262
- . replace ( / (?: ^ | \n ) ( [ \t ] .* ) (?: ( [ \n \t ] * ) \n (? ! [ \n \t ] ) ) ? / g, '$1$2' ) // more-indented lines aren't folded
263
- // ^ more-ind. ^ empty ^ capture next empty lines only at end of indent
264
- . replace ( / \n + / g, `$&${ indent } ` )
265
- const body = foldFlowLines (
266
- `${ start } ${ value } ${ end } ` ,
267
- indent ,
268
- FOLD_BLOCK ,
269
- getFoldOptions ( ctx , true )
270
- )
271
- return `${ header } \n${ indent } ${ body } `
277
+
278
+ value = value . replace ( / \n + / g, `$&${ indent } ` )
279
+ return `|${ header } \n${ indent } ${ start } ${ value } ${ end } `
272
280
}
273
281
274
282
function plainString (
0 commit comments