Factor out common code for UList and OList parsing into a separate
function. Refactored UList function; wrote OList function.
This commit is contained in:
@@ -287,13 +287,8 @@ parseBlockquote = do
|
|||||||
return (Blockquote parsedQuotedLines)
|
return (Blockquote parsedQuotedLines)
|
||||||
|
|
||||||
-- Parse a nested list item.
|
-- Parse a nested list item.
|
||||||
parseUListNested :: ReadP MdToken
|
parseListNested :: ReadP MdToken
|
||||||
parseUListNested = do
|
parseListNested = do
|
||||||
-- firstChar <- string " " <++ string "\t"
|
|
||||||
-- skipSpaces
|
|
||||||
-- restOfLine <- manyTill get (void (char '\n') <++ eof)
|
|
||||||
-- let restOfLineParsed = fst $ leftmostLongestParse parseLine restOfLine
|
|
||||||
-- return restOfLineParsed
|
|
||||||
let firstCharParser = string " " <++ string "\t"
|
let firstCharParser = string " " <++ string "\t"
|
||||||
let restOfLineParser = manyTill get (void (char '\n') <++ eof)
|
let restOfLineParser = manyTill get (void (char '\n') <++ eof)
|
||||||
lines <- greedyParse1 (firstCharParser *> restOfLineParser)
|
lines <- greedyParse1 (firstCharParser *> restOfLineParser)
|
||||||
@@ -308,7 +303,7 @@ parseUListLineItem = do
|
|||||||
skipSpaces
|
skipSpaces
|
||||||
restOfLine <- many1 parseListLineToken
|
restOfLine <- many1 parseListLineToken
|
||||||
void (char '\n') <++ eof
|
void (char '\n') <++ eof
|
||||||
nestedList <- parseUListNested <++ return (Unit "")
|
nestedList <- parseListNested <++ return (Unit "")
|
||||||
return $ Line [Line restOfLine, nestedList]
|
return $ Line [Line restOfLine, nestedList]
|
||||||
|
|
||||||
-- restOfLine <- manyTill get (void (char '\n') <++ eof)
|
-- restOfLine <- manyTill get (void (char '\n') <++ eof)
|
||||||
@@ -322,11 +317,27 @@ parseUListLineItem = do
|
|||||||
parseUListParaItem :: ReadP MdToken
|
parseUListParaItem :: ReadP MdToken
|
||||||
parseUListParaItem = do
|
parseUListParaItem = do
|
||||||
firstLine <- parseUListLineItem
|
firstLine <- parseUListLineItem
|
||||||
|
res <- parseListParaItemCommon
|
||||||
|
return $ Document (Para firstLine : res) -- I only wrap this in a document because I want some way of converting [MdToken] to MdToken, without any overhead. There is no other reason to wrap it in a Document.
|
||||||
|
|
||||||
|
-- Parse an unordered list paragraph item.
|
||||||
|
parseOListParaItem :: ReadP MdToken
|
||||||
|
parseOListParaItem = do
|
||||||
|
firstLine <- parseOListLineItem
|
||||||
|
res <- parseListParaItemCommon
|
||||||
|
return $ Document (Para firstLine : res) -- I only wrap this in a document because I want some way of converting [MdToken] to MdToken, without any overhead. There is no other reason to wrap it in a Document.
|
||||||
|
|
||||||
|
-- Common code for parsing list paragraph items.
|
||||||
|
-- A list paragraph item is defined as a line item, followed by an empty line, followed by one or more
|
||||||
|
-- lines indented by a space or tab.
|
||||||
|
-- A list paragraph item can also be a blockquote.
|
||||||
|
parseListParaItemCommon :: ReadP [MdToken]
|
||||||
|
parseListParaItemCommon = do
|
||||||
char '\n'
|
char '\n'
|
||||||
lines <- greedyParse1 ((string " " <|> string "\t") *> parseTillEol)
|
lines <- greedyParse1 ((string " " <|> string "\t") *> parseTillEol)
|
||||||
let res = fst $ leftmostLongestParse (greedyParse1 parsePara) (init $ unlines lines)
|
let res = fst $ leftmostLongestParse (greedyParse1 parsePara) (init $ unlines lines)
|
||||||
char '\n'
|
char '\n'
|
||||||
return $ Document (Para firstLine : res) -- I only wrap this in a document because I want some way of converting [MdToken] to MdToken, without any overhead. There is no other reason to wrap it in a Document.
|
return res -- I only wrap this in a document because I want some way of converting [MdToken] to MdToken, without any overhead. There is no other reason to wrap it in a Document.
|
||||||
|
|
||||||
-- 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 :: ReadP MdToken
|
parseUListItem :: ReadP MdToken
|
||||||
|
Reference in New Issue
Block a user