···
let buf = Buffer.create 256 in
let trailing_breaks = Buffer.create 16 in
656
-
(* Skip to content indentation, skipping empty lines *)
656
+
(* Skip to content indentation, skipping empty lines.
657
+
Returns the number of spaces actually skipped (important for detecting dedentation). *)
let rec skip_to_content_indent () =
if !content_indent > 0 then begin
659
-
(* Explicit indent - skip exactly content_indent spaces *)
660
+
(* Explicit indent - skip up to content_indent spaces *)
let spaces_skipped = ref 0 in
while !spaces_skipped < !content_indent && Input.next_is (( = ) ' ') t.input do
···
Buffer.add_char trailing_breaks '\n';
Input.consume_break t.input;
skip_to_content_indent ()
673
+
end else if !spaces_skipped < !content_indent then begin
674
+
(* Line starts with fewer spaces than content_indent - dedented *)
end else if Input.next_is_blank t.input then begin
(* Line has spaces beyond content_indent - check if rest is only blanks *)
···
skip_to_content_indent ()
(* Implicit indent - skip empty lines without consuming spaces *)
if Input.next_is_break t.input then begin
···
Input.consume_break t.input;
skip_to_content_indent ()
719
-
(* Has content - don't consume anything *)
724
+
(* Has content - don't consume anything, return 0 as we haven't skipped *)
727
+
(* Not at break or blank - return 0 *)
727
-
skip_to_content_indent ();
734
+
let spaces_skipped = skip_to_content_indent () in
(* Check if we're at content *)
if Input.is_eof t.input then ()
else if Input.at_document_boundary t.input then ()
733
-
(* Count leading spaces *)
734
-
let line_indent = ref 0 in
740
+
(* Count additional leading spaces beyond what was skipped *)
741
+
let extra_spaces = ref 0 in
while Input.next_is (( = ) ' ') t.input do
ignore (Input.next t.input)
740
-
(* For explicit indent, line_indent is extra beyond content_indent *)
741
-
if !content_indent > 0 then
742
-
line_indent := !content_indent + !line_indent;
747
+
(* Calculate actual line indentation *)
748
+
let line_indent = spaces_skipped + !extra_spaces in
(* Determine content indent from first content line (implicit case) *)
if !content_indent = 0 then begin
746
-
if !line_indent <= base_indent then begin
752
+
if line_indent <= base_indent then begin
(* No content - restore position conceptually *)
750
-
content_indent := !line_indent
756
+
content_indent := line_indent
753
-
if !line_indent < !content_indent then begin
759
+
if line_indent < !content_indent then begin
(* Dedented - done with content *)
···
(* Add extra indentation for literal *)
777
-
for _ = !content_indent + 1 to !line_indent do
783
+
for _ = !content_indent + 1 to line_indent do