Skip to content

Commit ecd4d5b

Browse files
Nils Carlsonjgm
authored andcommitted
OpenDocument writer: Implement figure numbering in captions (#4944)
Figure captions are now numbered 1, 2, 3, ... The format in the caption is "Figure 1: <caption>" and so on. This is necessary in order for libreoffice to generate an Illustration Index (Table of Figures) for included figures.
1 parent 05d52eb commit ecd4d5b

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/Text/Pandoc/Writers/OpenDocument.hs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,10 +411,22 @@ blockToOpenDocument o bs
411411
figure attr caption source title | null caption =
412412
withParagraphStyle o "Figure" [Para [Image attr caption (source,title)]]
413413
| otherwise = do
414+
id' <- gets stImageId
414415
imageDoc <- withParagraphStyle o "FigureWithCaption" [Para [Image attr caption (source,title)]]
415-
captionDoc <- withParagraphStyle o "FigureCaption" [Para caption]
416+
captionDoc <- numberedFigureCaption id' <$> inlinesToOpenDocument o caption
416417
return $ imageDoc $$ captionDoc
417418

419+
numberedFigureCaption :: Int -> Doc -> Doc
420+
numberedFigureCaption num caption =
421+
let t = text "Figure "
422+
r = num - 1
423+
s = inTags False "text:sequence" [ ("text:ref-name", "refIllustration" ++ show r),
424+
("text:name", "Illustration"),
425+
("text:formula", "ooow:Illustration+1"),
426+
("style:num-format", "1") ] $ text $ show num
427+
c = text ": "
428+
in inParagraphTagsWithStyle "FigureCaption" $ hcat [ t, s, c, caption ]
429+
418430
colHeadsToOpenDocument :: PandocMonad m
419431
=> WriterOptions -> [String] -> [[Block]]
420432
-> OD m Doc

test/writer.opendocument

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1880,7 +1880,7 @@ link in pointy braces</text:span></text:a>.</text:p>
18801880
<text:p text:style-name="First_20_paragraph">From “Voyage dans la Lune” by
18811881
Georges Melies (1902):</text:p>
18821882
<text:p text:style-name="FigureWithCaption"><draw:frame draw:name="img1"><draw:image xlink:href="lalune.jpg" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad" /></draw:frame></text:p>
1883-
<text:p text:style-name="FigureCaption">lalune</text:p>
1883+
<text:p text:style-name="FigureCaption">Figure <text:sequence text:ref-name="refIllustration0" text:name="Illustration" text:formula="ooow:Illustration+1" style:num-format="1">1</text:sequence>: lalune</text:p>
18841884
<text:p text:style-name="Text_20_body">Here is a movie
18851885
<draw:frame draw:name="img2"><draw:image xlink:href="movie.jpg" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad" /></draw:frame>
18861886
icon.</text:p>

0 commit comments

Comments
 (0)