Started working on blockquote parser

master
Aadhavan Srinivasan 23 hours ago
parent bfd627c763
commit 1df7f64aec

@ -48,7 +48,7 @@ instance Show MdToken where
show Linebreak = "<br>" show Linebreak = "<br>"
show SingleNewline = " " show SingleNewline = " "
show HorizontalRule = "---------" show HorizontalRule = "---------"
show (Blockquote token) = "BLOCK" ++ show token show (Blockquote token) = "<blockquote>" ++ show token ++ "</blockquote>"
show (UnordList tokens) = "UNORD" ++ concatMap show tokens show (UnordList tokens) = "UNORD" ++ concatMap show tokens
show (OrdList tokens) = "ORD" ++ concatMap show tokens show (OrdList tokens) = "ORD" ++ concatMap show tokens
show (Code code) = show code show (Code code) = show code
@ -148,7 +148,7 @@ parseSingleNewline = do
parseEscapedChar :: ReadP MdToken parseEscapedChar :: ReadP MdToken
parseEscapedChar = do parseEscapedChar = do
char '\\' char '\\'
escapedChar <- choice (map char specialChars) escapedChar <- choice (map char specialChars) -- Parse any of the special chars.
return (Unit [escapedChar]) return (Unit [escapedChar])
-- Parse a regular string as a Unit. -- Parse a regular string as a Unit.
@ -196,8 +196,14 @@ 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 blockquote, which is a greater-than sign followed by a paragraph.
parseBlockquote :: ReadP MdToken
parseBlockquote = do
char '>'
Blockquote <$> (parseBlockquote <++ parsePara) -- Parse another blockquote or a regular paragraph, wrap it in a blockquote.
-- Parse a document, which is multiple paragraphs. -- Parse a document, which is multiple paragraphs.
parseDocument :: ReadP MdToken parseDocument :: ReadP MdToken
parseDocument = do parseDocument = do
res <- manyTill (parseHeader <++ parsePara) eof res <- manyTill (parseHeader <++ parseBlockquote <++ parsePara) eof
return (Document res) return (Document res)

Loading…
Cancel
Save