git.iko.soy/typeable/pandoc
on master help sign in
Merge pull request #4184 from mb21/html-reader-figcaption

HTML Reader: be more forgiving about figcaption

commitacfa846aab4ed2c5acb00c9d4eab6b80c13114fd authorJohn MacFarlane <jgm@berkeley.edu> dateWed 27 Dec 2017, 13:33 (9 years ago) parent2e8722d9b54b94
2 files changed+39−4
src/Text/Pandoc/Readers/HTML.hs+7−4 test/command/4183.md+32
src/Text/Pandoc/Readers/HTML.hs+7−4
@@ -75,8 +75,8 @@ import Text.Pandoc.Options (
7575 ReaderOptions (readerExtensions, readerStripComments),
7676 extensionEnabled)
7777import Text.Pandoc.Parsing hiding ((<|>))
78−import Text.Pandoc.Shared (addMetaField, crFilter, escapeURI, extractSpaces,
79− safeRead, underlineSpan)
78+import Text.Pandoc.Shared (addMetaField, blocksToInlines', crFilter, escapeURI,
79+ extractSpaces, safeRead, underlineSpan)
8080import Text.Pandoc.Walk
8181import Text.Parsec.Error
8282import Text.TeXMath (readMathML, writeTeX)
@@ -600,8 +600,11 @@ pFigure = try $ do
600600 skipMany pBlank
601601 let pImg = (\x -> (Just x, Nothing)) <$>
602602 (pOptInTag "p" pImage <* skipMany pBlank)
603− pCapt = (\x -> (Nothing, Just x)) <$>
604− (pInTags "figcaption" inline <* skipMany pBlank)
603+ pCapt = (\x -> (Nothing, Just x)) <$> do
604+ skipMany pBlank
605+ bs <- pInTags "figcaption" block
606+ skipMany pBlank
607+ return $ blocksToInlines' $ B.toList bs
605608 pSkip = (Nothing, Nothing) <$ pSatisfy (not . matchTagClose "figure")
606609 res <- many (pImg <|> pCapt <|> pSkip)
607610 let mbimg = msum $ map fst res
test/command/4183.mdnew file+32
@@ -0,0 +1,32 @@
1+```
2+% pandoc -f html -t native
3+<figure>
4+ <img src="foo" alt="bar">
5+</figure>
6+^D
7+[Para [Image ("",[],[]) [] ("foo","fig:")]]
8+```
9+
10+```
11+% pandoc -f html -t native
12+<figure>
13+ <img src="foo" alt="bar">
14+ <figcaption>
15+ <div>
16+ baz
17+ </div>
18+ </figcaption>
19+</figure>
20+^D
21+[Para [Image ("",[],[]) [Str "baz"] ("foo","fig:")]]
22+```
23+
24+```
25+% pandoc -f html -t native
26+<figure>
27+ <img src="foo">
28+ <figcaption><p><em>baz</em></p></figcaption>
29+</figure>
30+^D
31+[Para [Image ("",[],[]) [Emph [Str "baz"]] ("foo","fig:")]]
32+```