From a0e8f6962478913ebebac34769af081374742219 Mon Sep 17 00:00:00 2001 From: Ryan Kavanagh Date: Sun, 7 Jun 2020 20:27:11 -0400 Subject: Add support for quoted lines --- gemini/mimeTextGemini.ml | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'gemini/mimeTextGemini.ml') diff --git a/gemini/mimeTextGemini.ml b/gemini/mimeTextGemini.ml index 2f4d5ca..ca4cd32 100644 --- a/gemini/mimeTextGemini.ml +++ b/gemini/mimeTextGemini.ml @@ -16,6 +16,7 @@ sig | Pre of string (* preformatted text line *) | Text of string (* plain text line *) | Ul of string (* unordered list item *) + | Quoted of string (* quoted text *) type gemini = gemini_line list @@ -39,6 +40,8 @@ sig val str_to_list_line : string -> gemini_line + val str_to_quoted_line : string -> gemini_line + val str_to_gemini : string -> gemini end @@ -57,6 +60,7 @@ struct | Pre of string | Text of string | Ul of string + | Quoted of string type gemini = gemini_line list @@ -69,6 +73,7 @@ struct | Pre s -> "Pre " ^ s | Text s -> "Text " ^ s | Ul s -> "Ul " ^ s + | Quoted s -> "Quoted " ^ s let gemini_line_to_canon_str = function | H1 s -> "# " ^ s @@ -79,6 +84,7 @@ struct | Pre s -> s | Text s -> s | Ul s -> "* " ^ s + | Quoted s -> ">" ^ s let gemini_to_str g = List.fold_right (fun l -> fun r -> (gemini_line_to_str l) ^ "\n" ^ r) g "" @@ -131,6 +137,7 @@ struct peek_char >>= function | Some '#' -> fail "text line cannot start with #" | Some '*' -> fail "text line cannot start with *" + | Some '>' -> fail "text line cannot start with >" | Some '`' -> (peek_string 3 >>= function | "```" -> fail "text line cannot start with ```" | _ -> take_line) @@ -161,6 +168,11 @@ struct let str_to_list_line = parse_string list_item_parser + let quoted_parser = + lift (fun x -> Ul x) (string ">" *> skip_spaces *> take_till_cr) + + let str_to_quoted_line = parse_string quoted_parser + let gemini : gemini_line list Angstrom.t = (* Because many tries each in order, we know that we will have a plain text line whenever we get to the text parser. As a result, @@ -173,6 +185,7 @@ struct <|> lift2 List.cons (header_parser <|> link_parser <|> list_item_parser + <|> quoted_parser <|> plain_text_parser) gemini <|> return []) "gemini" -- cgit v1.2.3