HTML Reader: parse figure and figcaption (#3813)
This commit is contained in:
parent
f9309bc46e
commit
7d9b782f73
2 changed files with 65 additions and 0 deletions
|
@ -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" [])
|
||||
|
|
45
test/command/html-read-figure.md
Normal file
45
test/command/html-read-figure.md
Normal file
|
@ -0,0 +1,45 @@
|
|||
```
|
||||
% pandoc -f html -t native
|
||||
<figure>
|
||||
<img src="foo.png" title="voyage">
|
||||
<figcaption>bar</figcaption>
|
||||
</figure>
|
||||
^D
|
||||
[Para [Image ("",[],[]) [Str "bar"] ("foo.png","fig:voyage")]]
|
||||
```
|
||||
|
||||
```
|
||||
% pandoc -f html -t native
|
||||
<figure>
|
||||
<figcaption>bar</figcaption>
|
||||
<img src="foo.png" title="voyage">
|
||||
</figure>
|
||||
^D
|
||||
[Para [Image ("",[],[]) [Str "bar"] ("foo.png","fig:voyage")]]
|
||||
```
|
||||
|
||||
```
|
||||
% pandoc -f html -t native
|
||||
<figure>
|
||||
<img src="foo.png" title="voyage">
|
||||
</figure>
|
||||
^D
|
||||
[Para [Image ("",[],[]) [] ("foo.png","fig:voyage")]]
|
||||
```
|
||||
|
||||
```
|
||||
% pandoc -f html -t native
|
||||
<figure>
|
||||
<p><img src="foo.png" title="voyage"></p>
|
||||
<figcaption>bar</figcaption>
|
||||
</figure>
|
||||
^D
|
||||
[Para [Image ("",[],[]) [Str "bar"] ("foo.png","fig:voyage")]]
|
||||
```
|
||||
|
||||
```
|
||||
% pandoc -f html -t native
|
||||
<figure><img src="foo.png" title="voyage" alt="this is ignored"><figcaption>bar <strong>baz</strong></figcaption></figure>
|
||||
^D
|
||||
[Para [Image ("",[],[]) [Str "bar",Space,Strong [Str "baz"]] ("foo.png","fig:voyage")]]
|
||||
```
|
Loading…
Add table
Reference in a new issue