More trying and backtracking; parse and discard extraneous spaces at

beginning of list
usingMegaparsec
Aadhavan Srinivasan 3 weeks ago
parent 80ef93bbc9
commit 0f04342867

@ -408,12 +408,12 @@ parseListParaItemCommon = do
-- Parse an unordered list item, which can be a line item or another list. -- Parse an unordered list item, which can be a line item or another list.
parseUListItem :: Parser MdToken parseUListItem :: Parser MdToken
parseUListItem = try parseUListParaItem <|> parseUListLineItem parseUListItem = space *> (try parseUListParaItem <|> parseUListLineItem)
-- Parse an unordered list. -- Parse an unordered list.
parseUnorderedList :: Parser MdToken parseUnorderedList :: Parser MdToken
parseUnorderedList = do parseUnorderedList = do
lineItems <- some parseUListItem lineItems <- some $ try parseUListItem
void (char '\n') <|> eof -- A list must end in an extra newline or eof void (char '\n') <|> eof -- A list must end in an extra newline or eof
return $ UnordList lineItems return $ UnordList lineItems
@ -425,6 +425,7 @@ parseOListItem = try parseOListParaItem <|> parseOListLineItem
-- Parses the first element of an ordered list, which must start with '1.' -- Parses the first element of an ordered list, which must start with '1.'
parseFirstOListItem :: Parser MdToken parseFirstOListItem :: Parser MdToken
parseFirstOListItem = do parseFirstOListItem = do
space
remaining <- getInput remaining <- getInput
when (take 2 (T.unpack remaining) /= "1.") empty when (take 2 (T.unpack remaining) /= "1.") empty
parseOListLineItem parseOListLineItem

Loading…
Cancel
Save