diff options
-rw-r--r-- | data/odt/styles.xml | 16 | ||||
-rw-r--r-- | src/Text/Pandoc/Writers/ODT.hs | 6 | ||||
-rw-r--r-- | src/Text/Pandoc/Writers/OpenDocument.hs | 11 | ||||
-rw-r--r-- | tests/tables.opendocument | 8 | ||||
-rw-r--r-- | tests/writer.opendocument | 3 |
5 files changed, 35 insertions, 9 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" /> </style:style> + <style:style style:name="TableCaption" style:family="paragraph" + style:parent-style-name="Caption" style:class="extra"> + </style:style> + <style:style style:name="FigureCaption" style:family="paragraph" + style:parent-style-name="Caption" style:class="extra"> + </style:style> + <style:style style:name="Figure" style:family="paragraph" + style:parent-style-name="Standard" style:class="extra"> + <style:paragraph-properties text:number-lines="false" + text:line-number="0" /> + </style:style> + <style:style style:name="FigureWithCaption" style:family="paragraph" + style:parent-style-name="Figure" style:class="extra"> + <style:paragraph-properties text:number-lines="false" + text:line-number="0" fo:keep-with-next="always" /> + </style:style> <style:style style:name="Index" style:family="paragraph" style:parent-style-name="Standard" style:class="index"> <style:paragraph-properties text:number-lines="false" diff --git a/src/Text/Pandoc/Writers/ODT.hs b/src/Text/Pandoc/Writers/ODT.hs index 2a4129512..81bbdaf3f 100644 --- a/src/Text/Pandoc/Writers/ODT.hs +++ b/src/Text/Pandoc/Writers/ODT.hs @@ -127,7 +127,7 @@ writeODT opts doc@(Pandoc meta _) = do return $ fromArchive archive'' transformPicMath :: WriterOptions -> 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 = [] - 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 @@ </table:table-cell> </table:table-row> </table:table> -<text:p text:style-name="Caption">Demonstration of simple table +<text:p text:style-name="TableCaption">Demonstration of simple table syntax.</text:p> <text:p text:style-name="First_20_paragraph">Simple table without caption:</text:p> @@ -197,7 +197,7 @@ spaces:</text:p> </table:table-cell> </table:table-row> </table:table> -<text:p text:style-name="Caption">Demonstration of simple table +<text:p text:style-name="TableCaption">Demonstration of simple table syntax.</text:p> <text:p text:style-name="First_20_paragraph">Multiline table with caption:</text:p> @@ -253,8 +253,8 @@ caption:</text:p> </table:table-cell> </table:table-row> </table:table> -<text:p text:style-name="Caption">Here's the caption. It may span multiple -lines.</text:p> +<text:p text:style-name="TableCaption">Here's the caption. It may span +multiple lines.</text:p> <text:p text:style-name="First_20_paragraph">Multiline table without caption:</text:p> <table:table table:name="Table5" table:style-name="Table5"> 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</text:span></text:a>.</text:p> <text:h text:style-name="Heading_20_1" text:outline-level="1">Images</text:h> <text:p text:style-name="First_20_paragraph">From “Voyage dans la Lune” by Georges Melies (1902):</text:p> -<text:p text:style-name="Text_20_body"><draw:frame draw:name="img1"><draw:image xlink:href="lalune.jpg" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad" /></draw:frame></text:p> +<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> +<text:p text:style-name="FigureCaption">lalune</text:p> <text:p text:style-name="Text_20_body">Here is a movie <draw:frame draw:name="img2"><draw:image xlink:href="movie.jpg" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad" /></draw:frame> icon.</text:p> |