@@ -38,13 +38,14 @@ tableToOpenXML blocksToOpenXML gridTable = do
39 let (Caption _maybeShortCaption captionBlocks) = caption
39 let (Caption _maybeShortCaption captionBlocks) = caption
40 let captionStr = stringify captionBlocks
40 let captionStr = stringify captionBlocks
41+ let aligns = map fst $ elems colspecs
41 captionXml <- if null captionBlocks
42 captionXml <- if null captionBlocks
42 then return []
43 then return []
43 else withParaPropM (pStyleM "Table Caption")
44 else withParaPropM (pStyleM "Table Caption")
44 $ blocksToOpenXML captionBlocks
45 $ blocksToOpenXML captionBlocks
45− head' <- cellGridToOpenXML blocksToOpenXML HeadRow thead
46+ head' <- cellGridToOpenXML blocksToOpenXML HeadRow aligns thead
46− bodies <- mapM (cellGridToOpenXML blocksToOpenXML BodyRow) tbodies
47+ bodies <- mapM (cellGridToOpenXML blocksToOpenXML BodyRow aligns) tbodies
47− foot' <- cellGridToOpenXML blocksToOpenXML FootRow tfoot
48+ foot' <- cellGridToOpenXML blocksToOpenXML FootRow aligns tfoot
49 let hasHeader = not . null . indices . partRowAttrs $ thead
50 let hasHeader = not . null . indices . partRowAttrs $ thead
50 let hasFooter = not . null . indices . partRowAttrs $ tfoot
51 let hasFooter = not . null . indices . partRowAttrs $ tfoot
@@ -110,12 +111,14 @@ tableLayout specs =
110cellGridToOpenXML :: PandocMonad m
111cellGridToOpenXML :: PandocMonad m
111 => ([Block] -> WS m [Content])
112 => ([Block] -> WS m [Content])
112 -> RowType
113 -> RowType
114 -> WS m [Element]
116 -> WS m [Element]
115−cellGridToOpenXML blocksToOpenXML rowType part@(Part _ _ rowAttrs) =
117+cellGridToOpenXML blocksToOpenXML rowType aligns part@(Part _ _ rowAttrs) =
116 if null (indices rowAttrs)
118 if null (indices rowAttrs)
117 then return mempty
119 then return mempty
118− else mapM (rowToOpenXML blocksToOpenXML) $ partToRows rowType part
120+ else mapM (rowToOpenXML blocksToOpenXML) $
121+ partToRows rowType aligns part
120data OOXMLCell
123data OOXMLCell
121 = OOXMLCell Attr Alignment RowSpan ColSpan [Block]
124 = OOXMLCell Attr Alignment RowSpan ColSpan [Block]
@@ -123,13 +126,17 @@ data OOXMLCell
124data OOXMLRow = OOXMLRow RowType Attr [OOXMLCell]
127data OOXMLRow = OOXMLRow RowType Attr [OOXMLCell]
126−partToRows :: RowType -> Part -> [OOXMLRow]
129+partToRows :: RowType -> [Alignment] -> Part -> [OOXMLRow]
127−partToRows rowType part =
130+partToRows rowType aligns part =
129− toOOXMLCell :: RowIndex -> ColIndex -> GridCell -> [OOXMLCell]
132+ toOOXMLCell :: Alignment -> RowIndex -> ColIndex -> GridCell -> [OOXMLCell]
130− toOOXMLCell ridx cidx = \case
133+ toOOXMLCell columnAlign ridx cidx = \case
131 ContentCell attr align rowspan colspan blocks ->
134 ContentCell attr align rowspan colspan blocks ->
135+ -- Respect non-default, cell specific alignment.
136+ let align' = case align of
137+ AlignDefault -> columnAlign
132− [OOXMLCell attr align rowspan colspan blocks]
139+ in [OOXMLCell attr align' rowspan colspan blocks]
133 ContinuationCell idx'@(ridx',cidx') | ridx /= ridx', cidx == cidx' ->
140 ContinuationCell idx'@(ridx',cidx') | ridx /= ridx', cidx == cidx' ->
134 case (partCellArray part)!idx' of
141 case (partCellArray part)!idx' of
135 (ContentCell _ _ _ colspan _) -> [OOXMLCellMerge colspan]
142 (ContentCell _ _ _ colspan _) -> [OOXMLCellMerge colspan]
@@ -138,7 +145,9 @@ partToRows rowType part =
138 _ -> mempty
145 _ -> mempty
139 mkRow :: (RowIndex, Attr) -> OOXMLRow
146 mkRow :: (RowIndex, Attr) -> OOXMLRow
140 mkRow (ridx, attr) = OOXMLRow rowType attr
147 mkRow (ridx, attr) = OOXMLRow rowType attr
141− . concatMap (uncurry $ toOOXMLCell ridx)
149+ . zipWith (\align -> uncurry $ toOOXMLCell align ridx)
143 . rowArray ridx
152 . rowArray ridx
144 $ partCellArray part
153 $ partCellArray part
@@ -155,9 +164,6 @@ rowToOpenXML blocksToOpenXML (OOXMLRow rowType _attr cells) = do
155 [mknode "w:tblHeader" [("w:val", "true")] ()] :)
164 [mknode "w:tblHeader" [("w:val", "true")] ()] :)
156 BodyRow -> id
165 BodyRow -> id
157 FootRow -> id
166 FootRow -> id
158− -- let align' = case align of
159− -- AlignDefault -> colAlign
161 return $ mknode "w:tr" [] (addTrPr xmlcells)
167 return $ mknode "w:tr" [] (addTrPr xmlcells)
163ooxmlCellToOpenXML :: PandocMonad m
169ooxmlCellToOpenXML :: PandocMonad m