diff --git a/data/odt/styles.xml b/data/odt/styles.xml index 1f1e2c5c8..623a89051 100644 --- a/data/odt/styles.xml +++ b/data/odt/styles.xml @@ -133,7 +133,7 @@ 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:style style:name="Table" style:family="paragraph" style:parent-style-name="Caption" style:class="extra"> </style:style> <style:style style:name="FigureCaption" style:family="paragraph" diff --git a/src/Text/Pandoc/Readers/Odt/ContentReader.hs b/src/Text/Pandoc/Readers/Odt/ContentReader.hs index 3a6a99237..2672b01ef 100644 --- a/src/Text/Pandoc/Readers/Odt/ContentReader.hs +++ b/src/Text/Pandoc/Readers/Odt/ContentReader.hs @@ -312,7 +312,7 @@ withNewStyle a = proc x -> do where isCodeStyle :: StyleName -> Bool isCodeStyle "Source_Text" = True - isCodeStyle _ = False + isCodeStyle _ = False inlineCode :: Inlines -> Inlines inlineCode = code . intercalate "" . map stringify . toList @@ -415,12 +415,18 @@ constructPara reader = proc blocks -> do fStyle <- readStyleByName -< blocks case fStyle of Left _ -> reader -< blocks + Right (styleName, _) | isTableCaptionStyle styleName -> do + blocks' <- reader -< blocks + arr tableCaptionP -< blocks' Right (_, style) -> do let modifier = getParaModifier style - blocks' <- reader -< blocks - arr modifier -<< blocks' - - + blocks' <- reader -< blocks + arr modifier -<< blocks' + where + isTableCaptionStyle :: StyleName -> Bool + isTableCaptionStyle "Table" = True + isTableCaptionStyle _ = False + tableCaptionP b = divWith ("", ["caption"], []) b type ListConstructor = [Blocks] -> Blocks @@ -904,6 +910,15 @@ read_text = matchChildContent' [ read_header ] >>^ doc +post_process :: Pandoc -> Pandoc +post_process (Pandoc m blocks) = + Pandoc m (post_process' blocks) + +post_process' :: [Block] -> [Block] +post_process' ((Table _ a w h r) : (Div ("", ["caption"], _) [Para inlines] ) : xs) = + (Table inlines a w h r) : ( post_process' xs ) +post_process' bs = bs + read_body :: OdtReader _x (Pandoc, MediaBag) read_body = executeIn NsOffice "body" $ executeIn NsOffice "text" @@ -911,4 +926,4 @@ read_body = executeIn NsOffice "body" $ proc inlines -> do txt <- read_text -< inlines state <- getExtraState -< () - returnA -< (txt, getMediaBag state) + returnA -< (post_process txt, getMediaBag state) diff --git a/src/Text/Pandoc/Writers/OpenDocument.hs b/src/Text/Pandoc/Writers/OpenDocument.hs index 42c151780..8bd0f469e 100644 --- a/src/Text/Pandoc/Writers/OpenDocument.hs +++ b/src/Text/Pandoc/Writers/OpenDocument.hs @@ -336,7 +336,7 @@ blockToOpenDocument o bs mapM_ addParaStyle . newPara $ paraHStyles ++ paraStyles captionDoc <- if null c then return empty - else withParagraphStyle o "TableCaption" [Para c] + else withParagraphStyle o "Table" [Para c] th <- if all null h then return empty else colHeadsToOpenDocument o name (map fst paraHStyles) h diff --git a/tests/Tests/Readers/Odt.hs b/tests/Tests/Readers/Odt.hs index d6ed48f8d..cd764dd62 100644 --- a/tests/Tests/Readers/Odt.hs +++ b/tests/Tests/Readers/Odt.hs @@ -157,6 +157,7 @@ namesOfTestsComparingToNative = [ "blockquote" , "referenceToListItem" , "referenceToText" , "simpleTable" + , "simpleTableWithCaption" -- , "table" , "unicode" , "unorderedList" diff --git a/tests/odt/native/simpleTableWithCaption.native b/tests/odt/native/simpleTableWithCaption.native new file mode 100644 index 000000000..18d68b772 --- /dev/null +++ b/tests/odt/native/simpleTableWithCaption.native @@ -0,0 +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 []] diff --git a/tests/odt/odt/simpleTableWithCaption.odt b/tests/odt/odt/simpleTableWithCaption.odt new file mode 100644 index 000000000..ec6fac894 Binary files /dev/null and b/tests/odt/odt/simpleTableWithCaption.odt differ diff --git a/tests/tables.opendocument b/tests/tables.opendocument index aa35abc91..0765bb783 100644 --- a/tests/tables.opendocument +++ b/tests/tables.opendocument @@ -63,8 +63,7 @@ </table:table-cell> </table:table-row> </table:table> -<text:p text:style-name="TableCaption">Demonstration of simple table -syntax.</text:p> +<text:p text:style-name="Table">Demonstration of simple table syntax.</text:p> <text:p text:style-name="First_20_paragraph">Simple table without caption:</text:p> <table:table table:name="Table2" table:style-name="Table2"> @@ -197,8 +196,7 @@ spaces:</text:p> </table:table-cell> </table:table-row> </table:table> -<text:p text:style-name="TableCaption">Demonstration of simple table -syntax.</text:p> +<text:p text:style-name="Table">Demonstration of simple table syntax.</text:p> <text:p text:style-name="First_20_paragraph">Multiline table with caption:</text:p> <table:table table:name="Table4" table:style-name="Table4"> @@ -253,8 +251,8 @@ caption:</text:p> </table:table-cell> </table:table-row> </table:table> -<text:p text:style-name="TableCaption">Here's the caption. It may span -multiple lines.</text:p> +<text:p text:style-name="Table">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">