diff options
author | Albert Krewinkel <albert@zeitkraut.de> | 2021-05-14 16:49:19 +0200 |
---|---|---|
committer | Albert Krewinkel <albert@zeitkraut.de> | 2021-05-14 16:49:19 +0200 |
commit | 3ec5726c9b7b9f7cc41ca5f26a80c347e20afc9a (patch) | |
tree | 21f0747af699389c875c86ee727606b01b68ae46 /src/Text/Pandoc/Writers | |
parent | 17d96404f5b6f5f080329e220a0784f10c364f2d (diff) | |
download | pandoc-3ec5726c9b7b9f7cc41ca5f26a80c347e20afc9a.tar.gz |
Docx writer: fix alignment for cells.
This fixes a regression introduced with the in the colspan/rowspan
changes that caused column alignments to be ignored. The column
alignment is used only if a default alignment is specified at the cell
level; otherwise the cell-level alignment takes precedence.
Diffstat (limited to 'src/Text/Pandoc/Writers')
-rw-r--r-- | src/Text/Pandoc/Writers/Docx/Table.hs | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/src/Text/Pandoc/Writers/Docx/Table.hs b/src/Text/Pandoc/Writers/Docx/Table.hs index ccc325fbe..e7fc82a10 100644 --- a/src/Text/Pandoc/Writers/Docx/Table.hs +++ b/src/Text/Pandoc/Writers/Docx/Table.hs @@ -38,13 +38,14 @@ tableToOpenXML blocksToOpenXML gridTable = do gridTable let (Caption _maybeShortCaption captionBlocks) = caption let captionStr = stringify captionBlocks + let aligns = map fst $ elems colspecs captionXml <- if null captionBlocks then return [] else withParaPropM (pStyleM "Table Caption") $ blocksToOpenXML captionBlocks - head' <- cellGridToOpenXML blocksToOpenXML HeadRow thead - bodies <- mapM (cellGridToOpenXML blocksToOpenXML BodyRow) tbodies - foot' <- cellGridToOpenXML blocksToOpenXML FootRow tfoot + head' <- cellGridToOpenXML blocksToOpenXML HeadRow aligns thead + bodies <- mapM (cellGridToOpenXML blocksToOpenXML BodyRow aligns) tbodies + foot' <- cellGridToOpenXML blocksToOpenXML FootRow aligns tfoot let hasHeader = not . null . indices . partRowAttrs $ thead let hasFooter = not . null . indices . partRowAttrs $ tfoot @@ -110,12 +111,14 @@ tableLayout specs = cellGridToOpenXML :: PandocMonad m => ([Block] -> WS m [Content]) -> RowType + -> [Alignment] -> Part -> WS m [Element] -cellGridToOpenXML blocksToOpenXML rowType part@(Part _ _ rowAttrs) = +cellGridToOpenXML blocksToOpenXML rowType aligns part@(Part _ _ rowAttrs) = if null (indices rowAttrs) then return mempty - else mapM (rowToOpenXML blocksToOpenXML) $ partToRows rowType part + else mapM (rowToOpenXML blocksToOpenXML) $ + partToRows rowType aligns part data OOXMLCell = OOXMLCell Attr Alignment RowSpan ColSpan [Block] @@ -123,13 +126,17 @@ data OOXMLCell data OOXMLRow = OOXMLRow RowType Attr [OOXMLCell] -partToRows :: RowType -> Part -> [OOXMLRow] -partToRows rowType part = +partToRows :: RowType -> [Alignment] -> Part -> [OOXMLRow] +partToRows rowType aligns part = let - toOOXMLCell :: RowIndex -> ColIndex -> GridCell -> [OOXMLCell] - toOOXMLCell ridx cidx = \case + toOOXMLCell :: Alignment -> RowIndex -> ColIndex -> GridCell -> [OOXMLCell] + toOOXMLCell columnAlign ridx cidx = \case ContentCell attr align rowspan colspan blocks -> - [OOXMLCell attr align rowspan colspan blocks] + -- Respect non-default, cell specific alignment. + let align' = case align of + AlignDefault -> columnAlign + _ -> align + in [OOXMLCell attr align' rowspan colspan blocks] ContinuationCell idx'@(ridx',cidx') | ridx /= ridx', cidx == cidx' -> case (partCellArray part)!idx' of (ContentCell _ _ _ colspan _) -> [OOXMLCellMerge colspan] @@ -138,7 +145,9 @@ partToRows rowType part = _ -> mempty mkRow :: (RowIndex, Attr) -> OOXMLRow mkRow (ridx, attr) = OOXMLRow rowType attr - . concatMap (uncurry $ toOOXMLCell ridx) + . mconcat + . zipWith (\align -> uncurry $ toOOXMLCell align ridx) + aligns . assocs . rowArray ridx $ partCellArray part @@ -155,9 +164,6 @@ rowToOpenXML blocksToOpenXML (OOXMLRow rowType _attr cells) = do [mknode "w:tblHeader" [("w:val", "true")] ()] :) BodyRow -> id FootRow -> id - -- let align' = case align of - -- AlignDefault -> colAlign - -- _ -> align return $ mknode "w:tr" [] (addTrPr xmlcells) ooxmlCellToOpenXML :: PandocMonad m |