diff --git a/src/MdToHTML.hs b/src/MdToHTML.hs index 7021075..0e7c024 100644 --- a/src/MdToHTML.hs +++ b/src/MdToHTML.hs @@ -37,6 +37,7 @@ data MdToken | Codeblock String | Link MdToken URL | Image MdToken ImgPath + | Figure MdToken ImgPath | Bold MdToken | Italic MdToken | Strikethrough MdToken @@ -59,6 +60,7 @@ instance Show MdToken where show (Codeblock code) = show code show (Link txt url) = "" ++ show txt ++ "" show (Image txt imgPath) = "\""" + show (Figure txt imgPath) = "
\""
" ++ show txt ++ "
" show (Bold token) = "" ++ show token ++ "" show (Italic token) = "" ++ show token ++ "" show (Strikethrough token) = "" ++ show token ++ "" @@ -205,6 +207,13 @@ parseImage = do char ')' return $ Image (Line altText) (ImgPath path) +parseFigure = do + img <- parseImage + void (string "\n\n") <++ eof + case img of + Image text path -> return $ Figure text path + _ -> return img + -- Parse an escaped character parseEscapedChar :: ReadP MdToken parseEscapedChar = do @@ -400,6 +409,7 @@ documentParsers = parseBlockquote, parseUnorderedList, parseOrderedList, + parseFigure, parsePara ] diff --git a/src/MdToHtmlTest.hs b/src/MdToHtmlTest.hs index 55cdbe4..3a514b9 100644 --- a/src/MdToHtmlTest.hs +++ b/src/MdToHtmlTest.hs @@ -102,8 +102,12 @@ codeTests = imageTests = TestList - [ check_equal "Image by itself" "

\"Image

" (convert "![Image 1](img.png)"), - check_equal "Image with text" "

This is an image \"Image

" (convert "This is an image ![Image 1](img.png)") + [ check_equal "Image with text" "

This is an image \"Image

" (convert "This is an image ![Image 1](img.png)") + ] + +figureTests = + TestList + [ check_equal "Image by itself" "
\"Image
Image 1
" (convert "![Image 1](img.png)") ] integrationTests = @@ -141,6 +145,7 @@ tests = unorderedListTests, orderedListTests, imageTests, + figureTests, codeTests, integrationTests ]