Skip to content

Commit

Permalink
Merge pull request #4184 from mb21/html-reader-figcaption
Browse files Browse the repository at this point in the history
HTML Reader: be more forgiving about figcaption
  • Loading branch information
jgm authored Dec 27, 2017
2 parents 2e8722d + 9b54b94 commit acfa846
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/Text/Pandoc/Readers/HTML.hs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ import Text.Pandoc.Options (
ReaderOptions (readerExtensions, readerStripComments),
extensionEnabled)
import Text.Pandoc.Parsing hiding ((<|>))
import Text.Pandoc.Shared (addMetaField, crFilter, escapeURI, extractSpaces,
safeRead, underlineSpan)
import Text.Pandoc.Shared (addMetaField, blocksToInlines', crFilter, escapeURI,
extractSpaces, safeRead, underlineSpan)
import Text.Pandoc.Walk
import Text.Parsec.Error
import Text.TeXMath (readMathML, writeTeX)
Expand Down Expand Up @@ -600,8 +600,11 @@ pFigure = try $ do
skipMany pBlank
let pImg = (\x -> (Just x, Nothing)) <$>
(pOptInTag "p" pImage <* skipMany pBlank)
pCapt = (\x -> (Nothing, Just x)) <$>
(pInTags "figcaption" inline <* skipMany pBlank)
pCapt = (\x -> (Nothing, Just x)) <$> do
skipMany pBlank
bs <- pInTags "figcaption" block
skipMany pBlank
return $ blocksToInlines' $ B.toList bs
pSkip = (Nothing, Nothing) <$ pSatisfy (not . matchTagClose "figure")
res <- many (pImg <|> pCapt <|> pSkip)
let mbimg = msum $ map fst res
Expand Down
32 changes: 32 additions & 0 deletions test/command/4183.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
```
% pandoc -f html -t native
<figure>
<img src="foo" alt="bar">
</figure>
^D
[Para [Image ("",[],[]) [] ("foo","fig:")]]
```

```
% pandoc -f html -t native
<figure>
<img src="foo" alt="bar">
<figcaption>
<div>
baz
</div>
</figcaption>
</figure>
^D
[Para [Image ("",[],[]) [Str "baz"] ("foo","fig:")]]
```

```
% pandoc -f html -t native
<figure>
<img src="foo">
<figcaption><p><em>baz</em></p></figcaption>
</figure>
^D
[Para [Image ("",[],[]) [Emph [Str "baz"]] ("foo","fig:")]]
```

0 comments on commit acfa846

Please sign in to comment.