Added figure implementation and tests
This commit is contained in:
@@ -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) = "<a href=\"" ++ getUrl url ++ "\">" ++ show txt ++ "</a>"
|
||||
show (Image txt imgPath) = "<img src=\"" ++ getPath imgPath ++ "\"" ++ " alt=\"" ++ show txt ++ "\" />"
|
||||
show (Figure txt imgPath) = "<figure><img src=\"" ++ getPath imgPath ++ "\" alt=\"" ++ show txt ++ "\"/><figcaption aria-hidden=\"true\">" ++ show txt ++ "</figcaption></figure>"
|
||||
show (Bold token) = "<b>" ++ show token ++ "</b>"
|
||||
show (Italic token) = "<i>" ++ show token ++ "</i>"
|
||||
show (Strikethrough token) = "<s>" ++ show token ++ "</s>"
|
||||
@@ -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
|
||||
]
|
||||
|
||||
|
@@ -102,8 +102,12 @@ codeTests =
|
||||
|
||||
imageTests =
|
||||
TestList
|
||||
[ check_equal "Image by itself" "<p><img src=\"img.png\" alt=\"Image 1\" /></p>" (convert ""),
|
||||
check_equal "Image with text" "<p>This is an image <img src=\"img.png\" alt=\"Image 1\" /></p>" (convert "This is an image ")
|
||||
[ check_equal "Image with text" "<p>This is an image <img src=\"img.png\" alt=\"Image 1\" /></p>" (convert "This is an image ")
|
||||
]
|
||||
|
||||
figureTests =
|
||||
TestList
|
||||
[ check_equal "Image by itself" "<figure><img src=\"img.png\" alt=\"Image 1\"/><figcaption aria-hidden=\"true\">Image 1</figcaption></figure>" (convert "")
|
||||
]
|
||||
|
||||
integrationTests =
|
||||
@@ -141,6 +145,7 @@ tests =
|
||||
unorderedListTests,
|
||||
orderedListTests,
|
||||
imageTests,
|
||||
figureTests,
|
||||
codeTests,
|
||||
integrationTests
|
||||
]
|
||||
|
Reference in New Issue
Block a user