git.iko.soy/typeable/pandoc
on master help sign in
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.

commitecd4d5b8d8cfda6a2cd8d8fb631e0d7c79bee363 authorNils Carlson <pyssling@ludd.ltu.se> dateWed 3 Oct 2018, 21:21 (8 years ago) parent05d52eb
2 files changed+14−2
src/Text/Pandoc/Writers/OpenDocument.hs+13−1 test/writer.opendocument+1−1
src/Text/Pandoc/Writers/OpenDocument.hs+13−1
@@ -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+
418430colHeadsToOpenDocument :: PandocMonad m
419431 => WriterOptions -> [String] -> [[Block]]
420432 -> OD m Doc
test/writer.opendocument+1−1
@@ -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
18811881Georges 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>
18861886icon.</text:p>