summaryrefslogtreecommitdiff
path: root/gemini
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--gemini/mimeTextGemini.ml23
1 files changed, 12 insertions, 11 deletions
diff --git a/gemini/mimeTextGemini.ml b/gemini/mimeTextGemini.ml
index ea370fd..e73be65 100644
--- a/gemini/mimeTextGemini.ml
+++ b/gemini/mimeTextGemini.ml
@@ -82,19 +82,20 @@ struct
List.fold_right (fun l -> fun r -> (gemini_line_to_str l) ^ "\n" ^ r) g ""
let gemini_to_canon_str g =
- let in_pre = ref false in
- let f l r =
- match (l, !in_pre) with
- | Pre s, true -> s ^ "\r\n" ^ r
+ let eol = "\r\n" in
+ let f (l : gemini_line) ((in_pre, r) : bool * string) =
+ match l, in_pre with
| Pre s, false ->
- let () = in_pre := true in
- "```\r\n" ^ s ^ "\r\n" ^ r
+ (true, s ^ eol ^ "```" ^ eol ^ r)
+ | Pre s, true ->
+ (true, s ^ eol ^ r)
| _, true ->
- let () = in_pre := false in
- "```\r\n" ^ (gemini_line_to_canon_str l) ^ "\r\n" ^ r
- | _, false -> (gemini_line_to_canon_str l) ^ "\r\n" ^ r
- in
- List.fold_right f g "\r\n"
+ (false, (gemini_line_to_canon_str l) ^ eol ^ "```" ^ eol ^ r)
+ | _, false ->
+ (false, (gemini_line_to_canon_str l) ^ eol ^ r) in
+ let (_, s) = List.fold_right f g (false, "") in
+ s
+
let parse_string p s =
match Angstrom.parse_string ~consume:All (p >>= return) s with