git.iko.soy/typeable/pandoc
on master help sign in
Merge pull request #2070 from lierdakil/odt-image-captions
a21c5baJohn MacFarlane
data/odt/styles.xml+16
@@ -133,6 +133,22 @@ xmlns:css3t="http://www.w3.org/TR/css3-text/" office:version="1.2">
133 style:font-size-complex="12pt"
133 style:font-size-complex="12pt"
134 style:font-style-complex="italic" />
134 style:font-style-complex="italic" />
135 </style:style>
135 </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>
136 <style:style style:name="Index" style:family="paragraph"
152 <style:style style:name="Index" style:family="paragraph"
137 style:parent-style-name="Standard" style:class="index">
153 style:parent-style-name="Standard" style:class="index">
138 <style:paragraph-properties text:number-lines="false"
154 <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
127 return $ fromArchive archive''
127 return $ fromArchive archive''
128
128
129transformPicMath :: WriterOptions -> IORef [Entry] -> Inline -> IO Inline
129transformPicMath :: WriterOptions -> IORef [Entry] -> Inline -> IO Inline
130−transformPicMath opts entriesRef (Image lab (src,_)) = do
130+transformPicMath opts entriesRef (Image lab (src,t)) = do
131 res <- fetchItem' (writerMediaBag opts) (writerSourceURL opts) src
131 res <- fetchItem' (writerMediaBag opts) (writerSourceURL opts) src
132 case res of
132 case res of
133 Left (_ :: E.SomeException) -> do
133 Left (_ :: E.SomeException) -> do
@@ -145,7 +145,9 @@ transformPicMath opts entriesRef (Image lab (src,_)) = do
145 epochtime <- floor `fmap` getPOSIXTime
145 epochtime <- floor `fmap` getPOSIXTime
146 let entry = toEntry newsrc epochtime $ toLazy img
146 let entry = toEntry newsrc epochtime $ toLazy img
147 modifyIORef entriesRef (entry:)
147 modifyIORef entriesRef (entry:)
148+ let fig | "fig:" `isPrefixOf` t = "fig:"
149+ | otherwise = ""
148− return $ Image lab (newsrc, tit')
150+ return $ Image lab (newsrc, fig++tit')
149transformPicMath _ entriesRef (Math t math) = do
151transformPicMath _ entriesRef (Math t math) = do
150 entries <- readIORef entriesRef
152 entries <- readIORef entriesRef
151 let dt = if t == InlineMath then DisplayInline else DisplayBlock
153 let dt = if t == InlineMath then DisplayInline else DisplayBlock
src/Text/Pandoc/Writers/OpenDocument.hs+9−2
@@ -288,6 +288,8 @@ blockToOpenDocument o bs
288 | Plain b <- bs = if null b
288 | Plain b <- bs = if null b
289 then return empty
289 then return empty
290 else inParagraphTags =<< inlinesToOpenDocument o b
290 else inParagraphTags =<< inlinesToOpenDocument o b
291+ | Para [Image c (s,'f':'i':'g':':':t)] <- bs
292+ = figure c s t
291 | Para b <- bs = if null b
293 | Para b <- bs = if null b
292 then return empty
294 then return empty
293 else inParagraphTags =<< inlinesToOpenDocument o b
295 else inParagraphTags =<< inlinesToOpenDocument o b
@@ -334,7 +336,7 @@ blockToOpenDocument o bs
334 mapM_ addParaStyle . newPara $ paraHStyles ++ paraStyles
336 mapM_ addParaStyle . newPara $ paraHStyles ++ paraStyles
335 captionDoc <- if null c
337 captionDoc <- if null c
336 then return empty
338 then return empty
337− else withParagraphStyle o "Caption" [Para c]
339+ else withParagraphStyle o "TableCaption" [Para c]
338 th <- if all null h
340 th <- if all null h
339 then return empty
341 then return empty
340 else colHeadsToOpenDocument o name (map fst paraHStyles) h
342 else colHeadsToOpenDocument o name (map fst paraHStyles) h
@@ -342,6 +344,12 @@ blockToOpenDocument o bs
342 return $ inTags True "table:table" [ ("table:name" , name)
344 return $ inTags True "table:table" [ ("table:name" , name)
343 , ("table:style-name", name)
345 , ("table:style-name", name)
344 ] (vcat columns $$ th $$ vcat tr) $$ captionDoc
346 ] (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
345
353
346colHeadsToOpenDocument :: WriterOptions -> String -> [String] -> [[Block]] -> State WriterState Doc
354colHeadsToOpenDocument :: WriterOptions -> String -> [String] -> [[Block]] -> State WriterState Doc
347colHeadsToOpenDocument o tn ns hs =
355colHeadsToOpenDocument o tn ns hs =
@@ -553,4 +561,3 @@ textStyleAttr s
553 ,("style:font-name-asian" ,"Courier New")
561 ,("style:font-name-asian" ,"Courier New")
554 ,("style:font-name-complex" ,"Courier New")]
562 ,("style:font-name-complex" ,"Courier New")]
555 | otherwise = []
563 | otherwise = []
556−
tests/tables.opendocument+4−4
@@ -63,7 +63,7 @@
63 </table:table-cell>
63 </table:table-cell>
64 </table:table-row>
64 </table:table-row>
65</table:table>
65</table:table>
66−<text:p text:style-name="Caption">Demonstration of simple table
66+<text:p text:style-name="TableCaption">Demonstration of simple table
67syntax.</text:p>
67syntax.</text:p>
68<text:p text:style-name="First_20_paragraph">Simple table without
68<text:p text:style-name="First_20_paragraph">Simple table without
69caption:</text:p>
69caption:</text:p>
@@ -197,7 +197,7 @@ spaces:</text:p>
197 </table:table-cell>
197 </table:table-cell>
198 </table:table-row>
198 </table:table-row>
199</table:table>
199</table:table>
200−<text:p text:style-name="Caption">Demonstration of simple table
200+<text:p text:style-name="TableCaption">Demonstration of simple table
201syntax.</text:p>
201syntax.</text:p>
202<text:p text:style-name="First_20_paragraph">Multiline table with
202<text:p text:style-name="First_20_paragraph">Multiline table with
203caption:</text:p>
203caption:</text:p>
@@ -253,8 +253,8 @@ caption:</text:p>
253 </table:table-cell>
253 </table:table-cell>
254 </table:table-row>
254 </table:table-row>
255</table:table>
255</table:table>
256−<text:p text:style-name="Caption">Here's the caption. It may span multiple
256+<text:p text:style-name="TableCaption">Here's the caption. It may span
257−lines.</text:p>
257+multiple lines.</text:p>
258<text:p text:style-name="First_20_paragraph">Multiline table without
258<text:p text:style-name="First_20_paragraph">Multiline table without
259caption:</text:p>
259caption:</text:p>
260<table:table table:name="Table5" table:style-name="Table5">
260<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>
1577<text:h text:style-name="Heading_20_1" text:outline-level="1">Images</text:h>
1577<text:h text:style-name="Heading_20_1" text:outline-level="1">Images</text:h>
1578<text:p text:style-name="First_20_paragraph">From “Voyage dans la Lune” by
1578<text:p text:style-name="First_20_paragraph">From “Voyage dans la Lune” by
1579Georges Melies (1902):</text:p>
1579Georges 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>
1581<text:p text:style-name="Text_20_body">Here is a movie
1582<text:p text:style-name="Text_20_body">Here is a movie
1582<draw:frame draw:name="img2"><draw:image xlink:href="movie.jpg" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad" /></draw:frame>
1583<draw:frame draw:name="img2"><draw:image xlink:href="movie.jpg" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad" /></draw:frame>
1583icon.</text:p>
1584icon.</text:p>