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) = "" show (OrdList tokens) = "
    " ++ concatMap (prepend "
  1. " . append "
  2. " . show) tokens ++ "
" + show (Checkbox isChecked) = "" show (Code code) = "" ++ strip (show code) ++ "" show (Table (thead : tokenGrid)) = "" ++ concatMap (\x -> "") thead ++ "" ++ "" ++ concatMap (\x -> "" ++ concatMap (\y -> "") x ++ "") tokenGrid ++ "
" ++ rstrip (show x) ++ "
" ++ rstrip (show y) ++ "
" show (Codeblock code) = "
" ++ 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