Wrote helper functions for parseBlockquote, to parse a quoted line and
multiple quoted lines.
This commit is contained in:
@@ -208,6 +208,36 @@ parsePara = do
|
|||||||
let parsedText = fst $ leftmostLongestParse parseLine text -- Parse a line
|
let parsedText = fst $ leftmostLongestParse parseLine text -- Parse a line
|
||||||
return (Para parsedText)
|
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.
|
-- Parse a blockquote, which is a greater-than sign followed by a paragraph.
|
||||||
parseBlockquote :: ReadP MdToken
|
parseBlockquote :: ReadP MdToken
|
||||||
parseBlockquote = do
|
parseBlockquote = do
|
||||||
|
Reference in New Issue
Block a user