diff options
author | Nils Carlson <nils@nilscarlson.se> | 2020-09-27 18:21:53 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-27 11:21:53 -0700 |
commit | ae4dcc0d4a66b30991babf080de23c08ac37cf90 (patch) | |
tree | 020c81046660601c2368712580acb9711a151755 /src | |
parent | 3abfcbeef73d87fc5ac78de2a0f94ee9c1968f80 (diff) | |
download | pandoc-ae4dcc0d4a66b30991babf080de23c08ac37cf90.tar.gz |
OpenDocument Writer: Implement table cell alignment (#6700)
Co-authored-by: Mauro Bieg <mb21@users.noreply.github.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/Writers/OpenDocument.hs | 38 |
1 files changed, 33 insertions, 5 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") |