From b2ba922638a296887fa29b780d12ea40814a86bb Mon Sep 17 00:00:00 2001 From: Nikolay Yakimov Date: Sun, 12 Apr 2015 00:34:03 +0300 Subject: ODT Writer: Figure captions Works pretty much the same as Word writer. Following styles are used for figures: Figure -- for figure with empty caption FigureWithCaption (based on Figure) -- for figure with caption FigureCaption (based on Caption) -- for figure captions Also, TableCaption (based on Caption) is used for table captions. We need FigureWithCaption to set keepWithNext, in order to keep caption with figure. --- data/odt/styles.xml | 16 ++++++++++++++++ src/Text/Pandoc/Writers/ODT.hs | 6 ++++-- src/Text/Pandoc/Writers/OpenDocument.hs | 11 +++++++++-- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/data/odt/styles.xml b/data/odt/styles.xml index ac0cbd742..32b918406 100644 --- a/data/odt/styles.xml +++ b/data/odt/styles.xml @@ -133,6 +133,22 @@ xmlns:css3t="http://www.w3.org/TR/css3-text/" office:version="1.2"> style:font-size-complex="12pt" style:font-style-complex="italic" /> + + + + + + + + + + IORef [Entry] -> Inline -> IO Inline -transformPicMath opts entriesRef (Image lab (src,_)) = do +transformPicMath opts entriesRef (Image lab (src,t)) = do res <- fetchItem' (writerMediaBag opts) (writerSourceURL opts) src case res of Left (_ :: E.SomeException) -> do @@ -145,7 +145,9 @@ transformPicMath opts entriesRef (Image lab (src,_)) = do epochtime <- floor `fmap` getPOSIXTime let entry = toEntry newsrc epochtime $ toLazy img modifyIORef entriesRef (entry:) - return $ Image lab (newsrc, tit') + let fig | "fig:" `isPrefixOf` t = "fig:" + | otherwise = "" + return $ Image lab (newsrc, fig++tit') transformPicMath _ entriesRef (Math t math) = do entries <- readIORef entriesRef let dt = if t == InlineMath then DisplayInline else DisplayBlock diff --git a/src/Text/Pandoc/Writers/OpenDocument.hs b/src/Text/Pandoc/Writers/OpenDocument.hs index 865b7fb35..aee656413 100644 --- a/src/Text/Pandoc/Writers/OpenDocument.hs +++ b/src/Text/Pandoc/Writers/OpenDocument.hs @@ -288,6 +288,8 @@ blockToOpenDocument o bs | Plain b <- bs = if null b then return empty else inParagraphTags =<< inlinesToOpenDocument o b + | Para [Image c (s,'f':'i':'g':':':t)] <- bs + = figure c s t | Para b <- bs = if null b then return empty else inParagraphTags =<< inlinesToOpenDocument o b @@ -334,7 +336,7 @@ blockToOpenDocument o bs mapM_ addParaStyle . newPara $ paraHStyles ++ paraStyles captionDoc <- if null c then return empty - else withParagraphStyle o "Caption" [Para c] + else withParagraphStyle o "TableCaption" [Para c] th <- if all null h then return empty else colHeadsToOpenDocument o name (map fst paraHStyles) h @@ -342,6 +344,12 @@ blockToOpenDocument o bs return $ inTags True "table:table" [ ("table:name" , name) , ("table:style-name", name) ] (vcat columns $$ th $$ vcat tr) $$ captionDoc + figure caption source title | null caption = + withParagraphStyle o "Figure" [Para [Image caption (source,title)]] + | otherwise = do + imageDoc <- withParagraphStyle o "FigureWithCaption" [Para [Image caption (source,title)]] + captionDoc <- withParagraphStyle o "FigureCaption" [Para caption] + return $ imageDoc $$ captionDoc colHeadsToOpenDocument :: WriterOptions -> String -> [String] -> [[Block]] -> State WriterState Doc colHeadsToOpenDocument o tn ns hs = @@ -553,4 +561,3 @@ textStyleAttr s ,("style:font-name-asian" ,"Courier New") ,("style:font-name-complex" ,"Courier New")] | otherwise = [] - -- cgit v1.2.3 From 66a8016bb3902c45216004e3c0392761e55756db Mon Sep 17 00:00:00 2001 From: Nikolay Yakimov Date: Sun, 12 Apr 2015 00:56:02 +0300 Subject: ODT Writer: Figure captions - Tests update --- tests/tables.opendocument | 8 ++++---- tests/writer.opendocument | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/tables.opendocument b/tests/tables.opendocument index ff304ef26..aa35abc91 100644 --- a/tests/tables.opendocument +++ b/tests/tables.opendocument @@ -63,7 +63,7 @@ -Demonstration of simple table +Demonstration of simple table syntax. Simple table without caption: @@ -197,7 +197,7 @@ spaces: -Demonstration of simple table +Demonstration of simple table syntax. Multiline table with caption: @@ -253,8 +253,8 @@ caption: -Here's the caption. It may span multiple -lines. +Here's the caption. It may span +multiple lines. Multiline table without caption: diff --git a/tests/writer.opendocument b/tests/writer.opendocument index ac436150d..af5bc2e32 100644 --- a/tests/writer.opendocument +++ b/tests/writer.opendocument @@ -1577,7 +1577,8 @@ link in pointy braces. Images From “Voyage dans la Lune” by Georges Melies (1902): - + +lalune Here is a movie icon. -- cgit v1.2.3