aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
authorMauro Bieg <mb21@users.noreply.github.com>2017-07-22 19:22:56 +0200
committerJohn MacFarlane <jgm@berkeley.edu>2017-07-22 19:22:56 +0200
commit7d9b782f73edfc49fbe6f0c3d6ce61328811cbc7 (patch)
tree84ad99c7d032c79e779273a5fd93e54185e9d846 /src/Text/Pandoc
parentf9309bc46e4bf24b3a1d53663297851394a89a3f (diff)
downloadpandoc-7d9b782f73edfc49fbe6f0c3d6ce61328811cbc7.tar.gz
HTML Reader: parse figure and figcaption (#3813)
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/Readers/HTML.hs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/Text/Pandoc/Readers/HTML.hs b/src/Text/Pandoc/Readers/HTML.hs
index 734973e33..3a0d6eb14 100644
--- a/src/Text/Pandoc/Readers/HTML.hs
+++ b/src/Text/Pandoc/Readers/HTML.hs
@@ -188,6 +188,7 @@ block = do
, pBody
, pDiv
, pPlain
+ , pFigure
, pRawHtmlBlock
]
trace (take 60 $ show $ B.toList res)
@@ -553,6 +554,25 @@ pPara = do
contents <- trimInlines <$> pInTags "p" inline
return $ B.para contents
+pFigure :: PandocMonad m => TagParser m Blocks
+pFigure = do
+ TagOpen _ _ <- pSatisfy (matchTagOpen "figure" [])
+ skipMany pBlank
+ let pImg = pOptInTag "p" pImage <* skipMany pBlank
+ pCapt = option mempty $ pInTags "figcaption" inline <* skipMany pBlank
+ pImgCapt = do
+ img <- pImg
+ cap <- pCapt
+ return (img, cap)
+ pCaptImg = do
+ cap <- pCapt
+ img <- pImg
+ return (img, cap)
+ (imgMany, caption) <- pImgCapt <|> pCaptImg
+ TagClose _ <- pSatisfy (matchTagClose "figure")
+ let (Image attr _ (url, tit)):_ = B.toList imgMany
+ return $ B.para $ B.imageWith attr url ("fig:" ++ tit) caption
+
pCodeBlock :: PandocMonad m => TagParser m Blocks
pCodeBlock = try $ do
TagOpen _ attr' <- pSatisfy (matchTagOpen "pre" [])