diff --git a/src/MdToHTML.hs b/src/MdToHTML.hs index c9712a7..4f2c99d 100644 --- a/src/MdToHTML.hs +++ b/src/MdToHTML.hs @@ -40,6 +40,7 @@ data MdToken | Blockquote [MdToken] | UnordList [MdToken] | OrdList [MdToken] + | Checkbox Bool | Code MdToken | Table [[MdToken]] | Codeblock MdToken @@ -66,6 +67,7 @@ instance Show MdToken where show (Blockquote tokens) = "
" ++ concatMap show tokens ++ "" show (UnordList tokens) = "
" ++ strip (show code) ++ "
"
show (Table (thead : tokenGrid)) = "" ++ rstrip (show x) ++ " | ") thead ++ "
---|
" ++ rstrip (show y) ++ " | ") x ++ "
" ++ show code ++ "
"
@@ -425,6 +427,15 @@ parseBlockquote = do
let parsedQuotedLines = leftmostLongestParse (some (parseBlockquote <|> parsePara)) (init $ unlines quotedLines) -- unlines joins the lines together with a newline, and adds a trailing newline. init removes the trailing newline.
return (Blockquote parsedQuotedLines)
+-- Parse a checkbox
+parseCheckbox :: Parser MdToken
+parseCheckbox = do
+ char '['
+ inside <- char ' ' <|> char 'x'
+ char ']'
+ space
+ return (if inside == 'x' then Checkbox True else Checkbox False)
+
-- Parse a nested list item.
parseListNested :: Parser MdToken
parseListNested = do
@@ -460,9 +471,12 @@ parseOListLineItem = do
parseListLineItemCommon :: Parser MdToken
parseListLineItemCommon = do
space
+ checkbox <- optional $ try parseCheckbox
restOfLine <- manyTill parseListLineToken (void (char '\n') <|> eof)
nestedList <- try parseListNested <|> return (Unit "")
- return $ Line [Line restOfLine, nestedList]
+ case checkbox of
+ Just box -> return $ Line [box, Line restOfLine, nestedList]
+ Nothing -> return $ Line [Line restOfLine, nestedList]
-- Parse an unordered list paragraph item.
parseUListParaItem :: Parser MdToken