git.iko.soy/typeable/pandoc
on master help sign in
Merge pull request #2070 from lierdakil/odt-image-captions

ODT Writer: Figure captions

commita21c5ba7c8a9d9b79aec92d5eaa4966cb7fe2052 authorJohn MacFarlane <jgm@berkeley.edu> dateSat 11 Apr 2015, 21:20 (12 years ago) parent9e16fb366a8016
5 files changed+35−9
data/odt/styles.xml+16 src/Text/Pandoc/Writers/ODT.hs+4−2 src/Text/Pandoc/Writers/OpenDocument.hs+9−2 tests/tables.opendocument+4−4 tests/writer.opendocument+2−1
data/odt/styles.xml+16
@@ -133,6 +133,22 @@ xmlns:css3t="http://www.w3.org/TR/css3-text/" office:version="1.2">
133133 style:font-size-complex="12pt"
134134 style:font-style-complex="italic" />
135135 </style:style>
136+ <style:style style:name="TableCaption" style:family="paragraph"
137+ style:parent-style-name="Caption" style:class="extra">
138+ </style:style>
139+ <style:style style:name="FigureCaption" style:family="paragraph"
140+ style:parent-style-name="Caption" style:class="extra">
141+ </style:style>
142+ <style:style style:name="Figure" style:family="paragraph"
143+ style:parent-style-name="Standard" style:class="extra">
144+ <style:paragraph-properties text:number-lines="false"
145+ text:line-number="0" />
146+ </style:style>
147+ <style:style style:name="FigureWithCaption" style:family="paragraph"
148+ style:parent-style-name="Figure" style:class="extra">
149+ <style:paragraph-properties text:number-lines="false"
150+ text:line-number="0" fo:keep-with-next="always" />
151+ </style:style>
136152 <style:style style:name="Index" style:family="paragraph"
137153 style:parent-style-name="Standard" style:class="index">
138154 <style:paragraph-properties text:number-lines="false"
src/Text/Pandoc/Writers/ODT.hs+4−2
@@ -127,7 +127,7 @@ writeODT opts doc@(Pandoc meta _) = do
127127 return $ fromArchive archive''
128128
129129transformPicMath :: WriterOptions -> IORef [Entry] -> Inline -> IO Inline
130−transformPicMath opts entriesRef (Image lab (src,_)) = do
130+transformPicMath opts entriesRef (Image lab (src,t)) = do
131131 res <- fetchItem' (writerMediaBag opts) (writerSourceURL opts) src
132132 case res of
133133 Left (_ :: E.SomeException) -> do
@@ -145,7 +145,9 @@ transformPicMath opts entriesRef (Image lab (src,_)) = do
145145 epochtime <- floor `fmap` getPOSIXTime
146146 let entry = toEntry newsrc epochtime $ toLazy img
147147 modifyIORef entriesRef (entry:)
148− return $ Image lab (newsrc, tit')
148+ let fig | "fig:" `isPrefixOf` t = "fig:"
149+ | otherwise = ""
150+ return $ Image lab (newsrc, fig++tit')
149151transformPicMath _ entriesRef (Math t math) = do
150152 entries <- readIORef entriesRef
151153 let dt = if t == InlineMath then DisplayInline else DisplayBlock
src/Text/Pandoc/Writers/OpenDocument.hs+9−2
@@ -288,6 +288,8 @@ blockToOpenDocument o bs
288288 | Plain b <- bs = if null b
289289 then return empty
290290 else inParagraphTags =<< inlinesToOpenDocument o b
291+ | Para [Image c (s,'f':'i':'g':':':t)] <- bs
292+ = figure c s t
291293 | Para b <- bs = if null b
292294 then return empty
293295 else inParagraphTags =<< inlinesToOpenDocument o b
@@ -334,7 +336,7 @@ blockToOpenDocument o bs
334336 mapM_ addParaStyle . newPara $ paraHStyles ++ paraStyles
335337 captionDoc <- if null c
336338 then return empty
337− else withParagraphStyle o "Caption" [Para c]
339+ else withParagraphStyle o "TableCaption" [Para c]
338340 th <- if all null h
339341 then return empty
340342 else colHeadsToOpenDocument o name (map fst paraHStyles) h
@@ -342,6 +344,12 @@ blockToOpenDocument o bs
342344 return $ inTags True "table:table" [ ("table:name" , name)
343345 , ("table:style-name", name)
344346 ] (vcat columns $$ th $$ vcat tr) $$ captionDoc
347+ figure caption source title | null caption =
348+ withParagraphStyle o "Figure" [Para [Image caption (source,title)]]
349+ | otherwise = do
350+ imageDoc <- withParagraphStyle o "FigureWithCaption" [Para [Image caption (source,title)]]
351+ captionDoc <- withParagraphStyle o "FigureCaption" [Para caption]
352+ return $ imageDoc $$ captionDoc
345353
346354colHeadsToOpenDocument :: WriterOptions -> String -> [String] -> [[Block]] -> State WriterState Doc
347355colHeadsToOpenDocument o tn ns hs =
@@ -553,4 +561,3 @@ textStyleAttr s
553561 ,("style:font-name-asian" ,"Courier New")
554562 ,("style:font-name-complex" ,"Courier New")]
555563 | otherwise = []
556−
tests/tables.opendocument+4−4
@@ -63,7 +63,7 @@
6363 </table:table-cell>
6464 </table:table-row>
6565</table:table>
66−<text:p text:style-name="Caption">Demonstration of simple table
66+<text:p text:style-name="TableCaption">Demonstration of simple table
6767syntax.</text:p>
6868<text:p text:style-name="First_20_paragraph">Simple table without
6969caption:</text:p>
@@ -197,7 +197,7 @@ spaces:</text:p>
197197 </table:table-cell>
198198 </table:table-row>
199199</table:table>
200−<text:p text:style-name="Caption">Demonstration of simple table
200+<text:p text:style-name="TableCaption">Demonstration of simple table
201201syntax.</text:p>
202202<text:p text:style-name="First_20_paragraph">Multiline table with
203203caption:</text:p>
@@ -253,8 +253,8 @@ caption:</text:p>
253253 </table:table-cell>
254254 </table:table-row>
255255</table:table>
256−<text:p text:style-name="Caption">Here's the caption. It may span multiple
257−lines.</text:p>
256+<text:p text:style-name="TableCaption">Here's the caption. It may span
257+multiple lines.</text:p>
258258<text:p text:style-name="First_20_paragraph">Multiline table without
259259caption:</text:p>
260260<table:table table:name="Table5" table:style-name="Table5">
tests/writer.opendocument+2−1
@@ -1577,7 +1577,8 @@ link in pointy braces</text:span></text:a>.</text:p>
15771577<text:h text:style-name="Heading_20_1" text:outline-level="1">Images</text:h>
15781578<text:p text:style-name="First_20_paragraph">From “Voyage dans la Lune” by
15791579Georges Melies (1902):</text:p>
1580−<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>
1580+<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>
1581+<text:p text:style-name="FigureCaption">lalune</text:p>
15811582<text:p text:style-name="Text_20_body">Here is a movie
15821583<draw:frame draw:name="img2"><draw:image xlink:href="movie.jpg" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad" /></draw:frame>
15831584icon.</text:p>