Skip to content

Commit

Permalink
OpenDocument writer: Implement figure numbering in captions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Nils Carlson committed Oct 2, 2018
1 parent 7bf8057 commit 5fb3b66
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/Text/Pandoc/Writers/OpenDocument.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5fb3b66

Please sign in to comment.