626
*/
627
private scanBlockScalar(style: '|' | '>'): void {
628
>
const start = this.pos;
yaml.ts
629
>
this.pos++; // skip '|' or '>'
630
>
631
>
// Parse header: optional indentation indicator (1-9) and chomping indicator (+/-)
632
>
let explicitIndent = 0;
633
>
let chomping: 'clip' | 'strip' | 'keep' = 'clip';
634
>
635
>
// The order of indent indicator and chomping indicator can vary (D83L test)
636
>
for (let i = 0; i < 2; i++) {
637
>
if (this.pos < this.input.length) {
638
>
const c = this.input[this.pos];
639
>
if (c >= '1' && c <= '9' && explicitIndent === 0) {
640
explicitIndent = parseInt(c, 10);
641
this.pos++;
642
>
} else if (c === '-' && chomping === 'clip') {
yaml.ts
643
chomping = 'strip';
644
this.pos++;
645
>
} else if (c === '+' && chomping === 'clip') {
yaml.ts
646
chomping = 'keep';
647
this.pos++;
648
}
650
>
}
651
>
652
>
// Skip any trailing whitespace on the header line
653
>
while (this.pos < this.input.length && (this.input[this.pos] === ' ' || this.input[this.pos] === '\t')) {
654
this.pos++;
655
}
657
>
// Skip optional comment on header line
658
>
if (this.pos < this.input.length && this.input[this.pos] === '#') {
659
while (this.pos < this.input.length && this.input[this.pos] !== '\n' && this.input[this.pos] !== '\r') {
660
this.pos++;
661
}
662
}
664
>
// Skip the header line's newline
665
>
this.consumeNewline();
666
>
667
>
// Determine the parent block's indentation level.
668
>
// Per YAML spec 8.1.1.1, content indentation = parent_block_indent + N
669
>
// where N is the explicit indent indicator (or auto-detected).
670
>
// Also used to establish a minimum content indent for auto-detection.
671
>
const parentBlockIndent = this.getParentBlockIndent(start);
672
>
673
>
// Compute the content indentation level
674
>
let contentIndent = explicitIndent > 0 ? parentBlockIndent + explicitIndent : 0;
675
>
const lines: string[] = [];
676
>
let trailingNewlines = 0;
677
>
678
>
while (this.pos < this.input.length) {
679
>
const lineStart = this.pos;
680
>
681
>
// Count leading spaces on this line (tabs are not valid YAML indentation)
682
>
let lineIndent = 0;
683
>
while (this.pos < this.input.length && this.input[this.pos] === ' ') {
684
>
lineIndent++;
685
>
this.pos++;
686
>
}
687
>
688
>
// Check if this is an empty or whitespace-only line
689
>
if (this.pos >= this.input.length || this.input[this.pos] === '\n' || this.input[this.pos] === '\r') {
690
if (contentIndent > 0 && lineIndent >= contentIndent) {
691
// Whitespace-only line with enough indent - preserve excess whitespace