From 3cd9f24935ac1c1e4970dee94542b978a7e00627 Mon Sep 17 00:00:00 2001 From: Rockingcool Date: Fri, 9 May 2025 16:12:09 -0500 Subject: [PATCH] Wrote helper functions for parseBlockquote, to parse a quoted line and multiple quoted lines. --- src/MdToHTML.hs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/MdToHTML.hs b/src/MdToHTML.hs index 7889863..20ac344 100644 --- a/src/MdToHTML.hs +++ b/src/MdToHTML.hs @@ -208,6 +208,36 @@ parsePara = do let parsedText = fst $ leftmostLongestParse parseLine text -- Parse a line return (Para parsedText) +-- Parse a line starting with '>', return the line except for the '>'. +parseQuotedLine :: ReadP String +parseQuotedLine = do + char '>' + restOfLine <- munch (/= '\n') + Text.ParserCombinators.ReadP.optional (char '\n') >> return "" + return restOfLine + +-- Parse many 'quoted lines' until I see a non-quoted line. +-- There HAS to be a better way of doing this, but I'm not sure what it is. +-- I rewrote it because I wanted it to consume all input, rather than being non-deterministic +-- and giving all intermediate parse results. +parseQuotedLines :: ReadP [String] +parseQuotedLines = + manyTill + ( do + look >>= \line -> + case line of + ('>' : _) -> parseQuotedLine + _ -> pfail + ) + ( ( do + look >>= \line -> + case line of + ('>' : _) -> pfail + _ -> return () + ) + <* eof + ) + -- Parse a blockquote, which is a greater-than sign followed by a paragraph. parseBlockquote :: ReadP MdToken parseBlockquote = do