My agentic slop goes here. Not intended for anyone else!

more

Changed files
+22 -3
stack
+22 -3
stack/river/lib/markdown_converter.ml
···
|> List.rev
with _ -> []
-
(** Normalize whitespace: collapse multiple spaces/tabs to single space *)
let normalize_whitespace s =
-
let s = Str.global_replace (Str.regexp "[ \t]+") " " s in
-
String.trim s
(** Clean up excessive newlines and normalize spacing *)
let cleanup_markdown s =
···
|> List.rev
with _ -> []
+
(** Normalize whitespace while preserving boundary spaces *)
let normalize_whitespace s =
+
let len = String.length s in
+
if len = 0 then ""
+
else
+
(* Check if original had leading/trailing whitespace *)
+
let has_leading = len > 0 && (s.[0] = ' ' || s.[0] = '\t' || s.[0] = '\n' || s.[0] = '\r') in
+
let has_trailing = len > 0 && (s.[len-1] = ' ' || s.[len-1] = '\t' || s.[len-1] = '\n' || s.[len-1] = '\r') in
+
+
(* Collapse multiple whitespace to single space *)
+
let normalized = Str.global_replace (Str.regexp "[ \t\n\r]+") " " s in
+
let trimmed = String.trim normalized in
+
+
(* If the trimmed result is empty but there was whitespace, return single space *)
+
if trimmed = "" && (has_leading || has_trailing) then " "
+
else
+
(* Add back boundary spaces if they existed *)
+
let result =
+
(if has_leading && trimmed <> "" then " " else "") ^
+
trimmed ^
+
(if has_trailing && trimmed <> "" then " " else "")
+
in
+
result
(** Clean up excessive newlines and normalize spacing *)
let cleanup_markdown s =