diff options
-rw-r--r-- | src/Text/Pandoc/Writers/OpenDocument.hs | 38 | ||||
-rw-r--r-- | test/command/table-with-cell-align.md | 45 | ||||
-rw-r--r-- | test/command/table-with-column-span.md | 40 |
3 files changed, 98 insertions, 25 deletions
diff --git a/src/Text/Pandoc/Writers/OpenDocument.hs b/src/Text/Pandoc/Writers/OpenDocument.hs index c7ee839b5..401ae5ed9 100644 --- a/src/Text/Pandoc/Writers/OpenDocument.hs +++ b/src/Text/Pandoc/Writers/OpenDocument.hs @@ -492,7 +492,6 @@ tableRowToOpenDocument o ns r = in inTagsIndented "table:table-row" . vcat <$> mapM (tableItemToOpenDocument o "TableRowCell") (zip ns c) - colspanAttrib :: ColSpan -> [(Text, Text)] colspanAttrib cs = case cs of @@ -505,17 +504,32 @@ rowspanAttrib rs = RowSpan 1 -> mempty RowSpan n -> [("table:number-rows-spanned", tshow n)] +alignAttrib :: Alignment -> [(Text,Text)] +alignAttrib a = case a of + AlignRight -> ("fo:text-align","end") : style + AlignCenter -> ("fo:text-align","center") : style + _ -> [] + where + style = [("style:justify-single-word","false")] + tableItemToOpenDocument :: PandocMonad m => WriterOptions -> Text -> (Text,Ann.Cell) -> OD m (Doc Text) -tableItemToOpenDocument o s (n,c) = - let (Ann.Cell _colspecs _colnum (Cell _ _ rs cs i) ) = c +tableItemToOpenDocument o s (n,c) = do + let (Ann.Cell _colspecs _colnum (Cell _ align rs cs i) ) = c csa = colspanAttrib cs rsa = rowspanAttrib rs + aa = alignAttrib align a = [ ("table:style-name" , s ) , ("office:value-type", "string" ) ] ++ csa ++ rsa - in inTags True "table:table-cell" a <$> - withParagraphStyle o n (map plainToPara i) + itemParaStyle <- case aa of + [] -> return 0 + _ -> paraStyleFromParent n aa + let itemParaStyle' = case itemParaStyle of + 0 -> n + x -> "P" <> tshow x + inTags True "table:table-cell" a <$> + withParagraphStyle o itemParaStyle' (map plainToPara i) -- | Convert a list of inline elements to OpenDocument. inlinesToOpenDocument :: PandocMonad m => WriterOptions -> [Inline] -> OD m (Doc Text) @@ -713,6 +727,20 @@ paraStyle attrs = do addParaStyle $ inTags True "style:style" (styleAttr <> attrs) paraProps return pn +paraStyleFromParent :: PandocMonad m => Text -> [(Text,Text)] -> OD m Int +paraStyleFromParent parent attrs = do + pn <- (+) 1 . length <$> gets stParaStyles + let styleAttr = [ ("style:name" , "P" <> tshow pn) + , ("style:family" , "paragraph") + , ("style:parent-style-name", parent)] + paraProps = if null attrs + then mempty + else selfClosingTag + "style:paragraph-properties" attrs + addParaStyle $ inTags True "style:style" styleAttr paraProps + return pn + + paraListStyle :: PandocMonad m => Int -> OD m Int paraListStyle l = paraStyle [("style:parent-style-name","Text_20_body") diff --git a/test/command/table-with-cell-align.md b/test/command/table-with-cell-align.md index d4ee72975..f6a454ad2 100644 --- a/test/command/table-with-cell-align.md +++ b/test/command/table-with-cell-align.md @@ -35,3 +35,48 @@ (TableFoot ("",[],[]) [])] ``` +``` +% pandoc -f native -t opendocument --quiet +[Table ("",[],[]) (Caption Nothing + []) + [(AlignDefault,ColWidthDefault) + ,(AlignDefault,ColWidthDefault) + ,(AlignDefault,ColWidthDefault) + ,(AlignDefault,ColWidthDefault)] + (TableHead ("",[],[]) + []) + [(TableBody ("",[],[]) (RowHeadColumns 0) + [] + [Row ("",[],[]) + [Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) + [Para [Str "1"]] + ,Cell ("",[],[]) AlignLeft (RowSpan 1) (ColSpan 1) + [Para [Str "2"]] + ,Cell ("",[],[]) AlignRight (RowSpan 1) (ColSpan 1) + [Para [Str "3"]] + ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) + [Para [Str "4"]]]])] + (TableFoot ("",[],[]) + [])] +^D +<table:table table:name="Table1" table:style-name="Table1"> + <table:table-column table:style-name="Table1.A" /> + <table:table-column table:style-name="Table1.B" /> + <table:table-column table:style-name="Table1.C" /> + <table:table-column table:style-name="Table1.D" /> + <table:table-row> + <table:table-cell table:style-name="TableRowCell" office:value-type="string"> + <text:p text:style-name="P1">1</text:p> + </table:table-cell> + <table:table-cell table:style-name="TableRowCell" office:value-type="string"> + <text:p text:style-name="Table_20_Contents">2</text:p> + </table:table-cell> + <table:table-cell table:style-name="TableRowCell" office:value-type="string"> + <text:p text:style-name="P2">3</text:p> + </table:table-cell> + <table:table-cell table:style-name="TableRowCell" office:value-type="string"> + <text:p text:style-name="Table_20_Contents">4</text:p> + </table:table-cell> + </table:table-row> +</table:table> +``` diff --git a/test/command/table-with-column-span.md b/test/command/table-with-column-span.md index f12319452..55977554f 100644 --- a/test/command/table-with-column-span.md +++ b/test/command/table-with-column-span.md @@ -142,47 +142,47 @@ [(TableBody ("",[],[]) (RowHeadColumns 0) [] [Row ("",[],[]) - [Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 8) + [Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 8) [Para [Strong [Str "Octet",Space,Str "no.",Space,Str "1"]]] - ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 8) + ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 8) [Para [Strong [Str "Octet",Space,Str "no.",Space,Str "2"]]]] ,Row ("",[],[]) - [Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) + [Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) [Para [Str "16"]] - ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) + ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) [Para [Str "15"]] - ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) + ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) [Para [Str "14"]] - ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) + ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) [Para [Str "13"]] - ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) + ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) [Para [Str "12"]] - ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) + ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) [Para [Str "11"]] - ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) + ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) [Para [Str "10"]] - ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) + ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) [Para [Str "9"]] - ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) + ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) [Para [Str "8"]] - ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) + ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) [Para [Str "7"]] - ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) + ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) [Para [Str "6"]] - ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) + ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) [Para [Str "5"]] - ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) + ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) [Para [Str "4"]] - ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) + ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) [Para [Str "3"]] - ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) + ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) [Para [Str "2"]] - ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1) + ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1) [Para [Str "1"]]] ,Row ("",[],[]) - [Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 8) + [Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 8) [Para [Str "Code",Space,Str "A"]] - ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 8) + ,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 8) [Para [Str "Code",Space,Str "B"]]]])] (TableFoot ("",[],[]) [])] |