Compare commits

...

2 Commits

@ -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)

@ -39,6 +39,23 @@ escapedCharTests =
check_equal "Should print literal asterisk in bold" "<p>This is a bolded asterisk - <b>*</b></p>" (convert "This is a bolded asterisk - **\\***") check_equal "Should print literal asterisk in bold" "<p>This is a bolded asterisk - <b>*</b></p>" (convert "This is a bolded asterisk - **\\***")
] ]
blockquoteTests =
TestList
[ check_equal "Should wrap para in blockquote" "<blockquote><p>What a <b>truly</b> <i>lovely</i> day!!!</p></blockquote>" (convert "> What a __truly__ _lovely_ day!!!"),
check_equal "Simple nested blockquotes" "<blockquote><p>Hello</p><blockquote><p>World</p></blockquote></blockquote>" (convert "> Hello\n>\n>> World"),
check_equal
"Nested blockquotes"
"<blockquote><p>Dorothy followed her through many \
\of the beautiful rooms in her castle.</p><blockquote><p>The Witch \
\bade her clean the pots and kettles and sweep the floor and keep the fire \
\fed with wood.</p></blockquote></blockquote>"
( convert
"> Dorothy followed her through many of the \
\beautiful rooms in her castle.\n> \n>> The Witch bade her \
\clean the pots and kettles and sweep the floor and keep the fire fed with wood."
)
]
integrationTests = integrationTests =
TestList TestList
[ check_equal "Integration 1" "<h1>Sample Markdown</h1><p>This is some basic, sample markdown.</p><h2><b>Second</b> <i>Heading</i></h2>" (convert "# Sample Markdown\n\n This is some basic, sample markdown.\n\n ## __Second__ _Heading_"), [ check_equal "Integration 1" "<h1>Sample Markdown</h1><p>This is some basic, sample markdown.</p><h2><b>Second</b> <i>Heading</i></h2>" (convert "# Sample Markdown\n\n This is some basic, sample markdown.\n\n ## __Second__ _Heading_"),
@ -55,6 +72,7 @@ tests =
boldTests, boldTests,
linkTests, linkTests,
escapedCharTests, escapedCharTests,
blockquoteTests,
integrationTests integrationTests
] ]

Loading…
Cancel
Save