From ecd4d5b8d8cfda6a2cd8d8fb631e0d7c79bee363 Mon Sep 17 00:00:00 2001 From: Nils Carlson Date: Wed, 3 Oct 2018 21:21:46 +0000 Subject: OpenDocument writer: Implement figure numbering in captions (#4944) Figure captions are now numbered 1, 2, 3, ... The format in the caption is "Figure 1: " and so on. This is necessary in order for libreoffice to generate an Illustration Index (Table of Figures) for included figures. --- src/Text/Pandoc/Writers/OpenDocument.hs | 14 +++++++++++++- test/writer.opendocument | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Text/Pandoc/Writers/OpenDocument.hs b/src/Text/Pandoc/Writers/OpenDocument.hs index cb29e390a..cd907bbea 100644 --- a/src/Text/Pandoc/Writers/OpenDocument.hs +++ b/src/Text/Pandoc/Writers/OpenDocument.hs @@ -411,10 +411,22 @@ blockToOpenDocument o bs figure attr caption source title | null caption = withParagraphStyle o "Figure" [Para [Image attr caption (source,title)]] | otherwise = do + id' <- gets stImageId imageDoc <- withParagraphStyle o "FigureWithCaption" [Para [Image attr caption (source,title)]] - captionDoc <- withParagraphStyle o "FigureCaption" [Para caption] + captionDoc <- numberedFigureCaption id' <$> inlinesToOpenDocument o caption return $ imageDoc $$ captionDoc +numberedFigureCaption :: Int -> Doc -> Doc +numberedFigureCaption num caption = + let t = text "Figure " + r = num - 1 + s = inTags False "text:sequence" [ ("text:ref-name", "refIllustration" ++ show r), + ("text:name", "Illustration"), + ("text:formula", "ooow:Illustration+1"), + ("style:num-format", "1") ] $ text $ show num + c = text ": " + in inParagraphTagsWithStyle "FigureCaption" $ hcat [ t, s, c, caption ] + colHeadsToOpenDocument :: PandocMonad m => WriterOptions -> [String] -> [[Block]] -> OD m Doc diff --git a/test/writer.opendocument b/test/writer.opendocument index 28c38ee1d..09a246b52 100644 --- a/test/writer.opendocument +++ b/test/writer.opendocument @@ -1880,7 +1880,7 @@ link in pointy braces. From “Voyage dans la Lune” by Georges Melies (1902): -lalune +Figure 1: lalune Here is a movie icon. -- cgit v1.2.3