@@ -183,6 +183,21 @@ function isWhitespace (c: number) {
183183 return c === CHAR_SPACE || c === CHAR_TAB
184184}
185185
186+ // Mirrors parser.testDocumentSeparator(): `---` and `...` are document
187+ // markers when followed by separation whitespace, a line break, or EOF.
188+ function startsWithDocumentSeparator ( string : string ) {
189+ const marker = string . charCodeAt ( 0 )
190+
191+ if ( ( marker !== CHAR_MINUS && marker !== 0x2E /* . */ ) ||
192+ string . charCodeAt ( 1 ) !== marker || string . charCodeAt ( 2 ) !== marker ) return false
193+
194+ if ( string . length === 3 ) return true
195+
196+ const following = string . charCodeAt ( 3 )
197+ return isWhitespace ( following ) ||
198+ following === CHAR_CARRIAGE_RETURN || following === CHAR_LINE_FEED
199+ }
200+
186201// Returns true if the character can be printed without escaping.
187202// From YAML 1.2: "any allowed characters known to be non-printable
188203// should also be escaped. [However,] This isn’t mandatory"
@@ -358,7 +373,7 @@ function chooseScalarStyle (state: PresenterState, string: string, layout: Retur
358373 let previousLineBreak = - 1 // count the first line correctly
359374 // Document markers are recognized as whole tokens at the start of a line,
360375 // so character-level plain-scalar checks alone cannot reject them.
361- let plain = string !== '---' && string !== '...' &&
376+ let plain = ! startsWithDocumentSeparator ( string ) &&
362377 isPlainSafeAtStart ( string , inblock ) &&
363378 isPlainSafeLast ( codePointAt ( string , string . length - 1 ) )
364379
0 commit comments