git.iko.soy/typeable/pandoc
on master help sign in
[odt] Infer table's caption from the paragraph (#3224)
015deadhubertp-lshift
data/odt/styles.xml+1−1
@@ -133,7 +133,7 @@ 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"
136+ <style:style style:name="Table" style:family="paragraph"
137 style:parent-style-name="Caption" style:class="extra">
137 style:parent-style-name="Caption" style:class="extra">
138 </style:style>
138 </style:style>
139 <style:style style:name="FigureCaption" style:family="paragraph"
139 <style:style style:name="FigureCaption" style:family="paragraph"
src/Text/Pandoc/Readers/Odt/ContentReader.hs+21−6
@@ -312,7 +312,7 @@ withNewStyle a = proc x -> do
312 where
312 where
313 isCodeStyle :: StyleName -> Bool
313 isCodeStyle :: StyleName -> Bool
314 isCodeStyle "Source_Text" = True
314 isCodeStyle "Source_Text" = True
315− isCodeStyle _ = False
315+ isCodeStyle _ = False
316
316
317 inlineCode :: Inlines -> Inlines
317 inlineCode :: Inlines -> Inlines
318 inlineCode = code . intercalate "" . map stringify . toList
318 inlineCode = code . intercalate "" . map stringify . toList
@@ -415,12 +415,18 @@ constructPara reader = proc blocks -> do
415 fStyle <- readStyleByName -< blocks
415 fStyle <- readStyleByName -< blocks
416 case fStyle of
416 case fStyle of
417 Left _ -> reader -< blocks
417 Left _ -> reader -< blocks
418+ Right (styleName, _) | isTableCaptionStyle styleName -> do
419+ blocks' <- reader -< blocks
420+ arr tableCaptionP -< blocks'
418 Right (_, style) -> do
421 Right (_, style) -> do
419 let modifier = getParaModifier style
422 let modifier = getParaModifier style
420− blocks' <- reader -< blocks
423+ blocks' <- reader -< blocks
421− arr modifier -<< blocks'
424+ arr modifier -<< blocks'
422−
425+ where
423−
426+ isTableCaptionStyle :: StyleName -> Bool
427+ isTableCaptionStyle "Table" = True
428+ isTableCaptionStyle _ = False
429+ tableCaptionP b = divWith ("", ["caption"], []) b
424
430
425type ListConstructor = [Blocks] -> Blocks
431type ListConstructor = [Blocks] -> Blocks
426
432
@@ -904,6 +910,15 @@ read_text = matchChildContent' [ read_header
904 ]
910 ]
905 >>^ doc
911 >>^ doc
906
912
913+post_process :: Pandoc -> Pandoc
914+post_process (Pandoc m blocks) =
915+ Pandoc m (post_process' blocks)
916+
917+post_process' :: [Block] -> [Block]
918+post_process' ((Table _ a w h r) : (Div ("", ["caption"], _) [Para inlines] ) : xs) =
919+ (Table inlines a w h r) : ( post_process' xs )
920+post_process' bs = bs
921+
907read_body :: OdtReader _x (Pandoc, MediaBag)
922read_body :: OdtReader _x (Pandoc, MediaBag)
908read_body = executeIn NsOffice "body"
923read_body = executeIn NsOffice "body"
909 $ executeIn NsOffice "text"
924 $ executeIn NsOffice "text"
@@ -911,4 +926,4 @@ read_body = executeIn NsOffice "body"
911 $ proc inlines -> do
926 $ proc inlines -> do
912 txt <- read_text -< inlines
927 txt <- read_text -< inlines
913 state <- getExtraState -< ()
928 state <- getExtraState -< ()
914− returnA -< (txt, getMediaBag state)
929+ returnA -< (post_process txt, getMediaBag state)
src/Text/Pandoc/Writers/OpenDocument.hs+1−1
@@ -336,7 +336,7 @@ blockToOpenDocument o bs
336 mapM_ addParaStyle . newPara $ paraHStyles ++ paraStyles
336 mapM_ addParaStyle . newPara $ paraHStyles ++ paraStyles
337 captionDoc <- if null c
337 captionDoc <- if null c
338 then return empty
338 then return empty
339− else withParagraphStyle o "TableCaption" [Para c]
339+ else withParagraphStyle o "Table" [Para c]
340 th <- if all null h
340 th <- if all null h
341 then return empty
341 then return empty
342 else colHeadsToOpenDocument o name (map fst paraHStyles) h
342 else colHeadsToOpenDocument o name (map fst paraHStyles) h
tests/Tests/Readers/Odt.hs+1
@@ -157,6 +157,7 @@ namesOfTestsComparingToNative = [ "blockquote"
157 , "referenceToListItem"
157 , "referenceToListItem"
158 , "referenceToText"
158 , "referenceToText"
159 , "simpleTable"
159 , "simpleTable"
160+ , "simpleTableWithCaption"
160-- , "table"
161-- , "table"
161 , "unicode"
162 , "unicode"
162 , "unorderedList"
163 , "unorderedList"
tests/odt/native/simpleTableWithCaption.nativenew file+1
@@ -0,0 +1 @@
1+[Table [Str "Table",Space,Str "1:",Space,Str "Some",Space,Str "caption",Space,Str "for",Space,Str "a",Space,Str "table"] [AlignDefault,AlignDefault] [0.0,0.0] [[],[]] [[[Plain [Str "Content"]],[Plain [Str "More",Space,Str "content"]]]],Para []]
tests/odt/odt/simpleTableWithCaption.odtnew file

Binary file not shown.

tests/tables.opendocument+4−6
@@ -63,8 +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="TableCaption">Demonstration of simple table
66+<text:p text:style-name="Table">Demonstration of simple table syntax.</text:p>
67−syntax.</text:p>
68<text:p text:style-name="First_20_paragraph">Simple table without
67<text:p text:style-name="First_20_paragraph">Simple table without
69caption:</text:p>
68caption:</text:p>
70<table:table table:name="Table2" table:style-name="Table2">
69<table:table table:name="Table2" table:style-name="Table2">
@@ -197,8 +196,7 @@ spaces:</text:p>
197 </table:table-cell>
196 </table:table-cell>
198 </table:table-row>
197 </table:table-row>
199</table:table>
198</table:table>
200−<text:p text:style-name="TableCaption">Demonstration of simple table
199+<text:p text:style-name="Table">Demonstration of simple table syntax.</text:p>
201−syntax.</text:p>
202<text:p text:style-name="First_20_paragraph">Multiline table with
200<text:p text:style-name="First_20_paragraph">Multiline table with
203caption:</text:p>
201caption:</text:p>
204<table:table table:name="Table4" table:style-name="Table4">
202<table:table table:name="Table4" table:style-name="Table4">
@@ -253,8 +251,8 @@ caption:</text:p>
253 </table:table-cell>
251 </table:table-cell>
254 </table:table-row>
252 </table:table-row>
255</table:table>
253</table:table>
256−<text:p text:style-name="TableCaption">Here's the caption. It may span
254+<text:p text:style-name="Table">Here's the caption. It may span multiple
257−multiple lines.</text:p>
255+lines.</text:p>
258<text:p text:style-name="First_20_paragraph">Multiline table without
256<text:p text:style-name="First_20_paragraph">Multiline table without
259caption:</text:p>
257caption:</text:p>
260<table:table table:name="Table5" table:style-name="Table5">
258<table:table table:name="Table5" table:style-name="Table5">