···653653 let buf = Buffer.create 256 in
654654 let trailing_breaks = Buffer.create 16 in
655655656656- (* Skip to content indentation, skipping empty lines *)
656656+ (* Skip to content indentation, skipping empty lines.
657657+ Returns the number of spaces actually skipped (important for detecting dedentation). *)
657658 let rec skip_to_content_indent () =
658659 if !content_indent > 0 then begin
659659- (* Explicit indent - skip exactly content_indent spaces *)
660660+ (* Explicit indent - skip up to content_indent spaces *)
660661 let spaces_skipped = ref 0 in
661662 while !spaces_skipped < !content_indent && Input.next_is (( = ) ' ') t.input do
662663 incr spaces_skipped;
···669670 Buffer.add_char trailing_breaks '\n';
670671 Input.consume_break t.input;
671672 skip_to_content_indent ()
673673+ end else if !spaces_skipped < !content_indent then begin
674674+ (* Line starts with fewer spaces than content_indent - dedented *)
675675+ !spaces_skipped
672676 end else if Input.next_is_blank t.input then begin
673677 (* Line has spaces beyond content_indent - check if rest is only blanks *)
674678 let idx = ref 0 in
···691695 skip_to_content_indent ()
692696 | _ ->
693697 (* Has content *)
694694- ())
695695- end
698698+ !content_indent)
699699+ end else
700700+ !content_indent
696701 end else begin
697702 (* Implicit indent - skip empty lines without consuming spaces *)
698703 if Input.next_is_break t.input then begin
···716721 Input.consume_break t.input;
717722 skip_to_content_indent ()
718723 | _ ->
719719- (* Has content - don't consume anything *)
720720- ()
721721- end
724724+ (* Has content - don't consume anything, return 0 as we haven't skipped *)
725725+ 0
726726+ end else
727727+ (* Not at break or blank - return 0 *)
728728+ 0
722729 end
723730 in
724731725732 (* Read content *)
726733 let rec read_lines () =
727727- skip_to_content_indent ();
734734+ let spaces_skipped = skip_to_content_indent () in
728735729736 (* Check if we're at content *)
730737 if Input.is_eof t.input then ()
731738 else if Input.at_document_boundary t.input then ()
732739 else begin
733733- (* Count leading spaces *)
734734- let line_indent = ref 0 in
740740+ (* Count additional leading spaces beyond what was skipped *)
741741+ let extra_spaces = ref 0 in
735742 while Input.next_is (( = ) ' ') t.input do
736736- incr line_indent;
743743+ incr extra_spaces;
737744 ignore (Input.next t.input)
738745 done;
739746740740- (* For explicit indent, line_indent is extra beyond content_indent *)
741741- if !content_indent > 0 then
742742- line_indent := !content_indent + !line_indent;
747747+ (* Calculate actual line indentation *)
748748+ let line_indent = spaces_skipped + !extra_spaces in
743749744750 (* Determine content indent from first content line (implicit case) *)
745751 if !content_indent = 0 then begin
746746- if !line_indent <= base_indent then begin
752752+ if line_indent <= base_indent then begin
747753 (* No content - restore position conceptually *)
748754 ()
749755 end else
750750- content_indent := !line_indent
756756+ content_indent := line_indent
751757 end;
752758753753- if !line_indent < !content_indent then begin
759759+ if line_indent < !content_indent then begin
754760 (* Dedented - done with content *)
755761 ()
756762 end else begin
···774780775781 (* Add extra indentation for literal *)
776782 if literal then begin
777777- for _ = !content_indent + 1 to !line_indent do
783783+ for _ = !content_indent + 1 to line_indent do
778784 Buffer.add_char buf ' '
779785 done
780786 end;