File tree Expand file tree Collapse file tree 2 files changed +74
-1
lines changed Expand file tree Collapse file tree 2 files changed +74
-1
lines changed Original file line number Diff line number Diff line change @@ -993,7 +993,31 @@ blockToHtml opts (DefinitionList lst) = do
993993 defList opts contents
994994blockToHtml opts (Table attr caption colspecs thead tbody tfoot) =
995995 tableToHtml opts (Ann. toTable attr caption colspecs thead tbody tfoot)
996- blockToHtml opts (Figure attrs _ body) = blockToHtml opts $ Div attrs body
996+ blockToHtml opts (Figure attrs (Caption _ captBody) body) = do
997+ html5 <- gets stHtml5
998+
999+ htmlAttrs <- attrsToHtml opts attrs
1000+ contents <- blockListToHtml opts body
1001+
1002+ if html5
1003+ then do
1004+ capt <- if null captBody
1005+ then return mempty
1006+ else blockListToHtml opts captBody >>= \ cb -> return $ mconcat
1007+ [ H5. figcaption cb
1008+ , nl opts ]
1009+ return $ foldl (!) H5. figure htmlAttrs $ mconcat
1010+ [nl opts, contents, nl opts, capt]
1011+ else do
1012+ capt <- if null captBody
1013+ then return mempty
1014+ else blockListToHtml opts captBody >>= \ cb -> return $
1015+ mconcat
1016+ [ (H. div ! A. class_ " figcaption" ) cb
1017+ , nl opts ]
1018+
1019+ return $ foldl (!) H. div (A. class_ " float" : htmlAttrs) $ mconcat
1020+ [nl opts, contents, nl opts, capt]
9971021
9981022tableToHtml :: PandocMonad m
9991023 => WriterOptions
Original file line number Diff line number Diff line change 1+ HTML5 figure with caption and content.
2+
3+ ```
4+ % pandoc -f native -t html5
5+ [Figure ("fig-id",[],[]) (Caption Nothing [Plain [Str "caption"]]) [Para [Str "content"]]]
6+
7+ ^D
8+ <figure id="fig-id">
9+ <p>content</p>
10+ <figcaption>caption</figcaption>
11+ </figure>
12+ ```
13+
14+ HTML5 figure with NO caption and content.
15+
16+ ```
17+ % pandoc -f native -t html5
18+ [Figure ("fig-id",[],[]) (Caption Nothing []) [Para [Str "content"]]]
19+
20+ ^D
21+ <figure id="fig-id">
22+ <p>content</p>
23+ </figure>
24+ ```
25+
26+ HTML4 figure with caption and content.
27+
28+ ```
29+ % pandoc -f native -t html4
30+ [Figure ("fig-id",[],[]) (Caption Nothing [Plain [Str "caption"]]) [Para [Str "content"]]]
31+
32+ ^D
33+ <div class="float" id="fig-id">
34+ <p>content</p>
35+ <div class="figcaption">caption</div>
36+ </div>
37+ ```
38+
39+ HTML4 figure with NO caption and content.
40+
41+ ```
42+ % pandoc -f native -t html4
43+ [Figure ("fig-id",[],[]) (Caption Nothing []) [Para [Str "content"]]]
44+
45+ ^D
46+ <div class="float" id="fig-id">
47+ <p>content</p>
48+ </div>
49+ ```
You can’t perform that action at this time.
0 commit comments