git.iko.soy/typeable/pandoc
on master help sign in
Docx writer: handle tables in table cells.
b02c25bJohn MacFarlane
src/Text/Pandoc/Writers/Docx.hs+7−2
@@ -945,8 +945,13 @@ blockToOpenXML' opts (Table caption aligns widths headers rows) = do
945 else withParaProp (pCustomStyle "TableCaption")
945 else withParaProp (pCustomStyle "TableCaption")
946 $ blockToOpenXML opts (Para caption)
946 $ blockToOpenXML opts (Para caption)
947 let alignmentFor al = mknode "w:jc" [("w:val",alignmentToString al)] ()
947 let alignmentFor al = mknode "w:jc" [("w:val",alignmentToString al)] ()
948+ -- Table cells require a <w:p> element, even an empty one!
949+ -- Not in the spec but in Word 2007, 2010. See #4953.
948− let cellToOpenXML (al, cell) = withParaProp (alignmentFor al)
950+ let cellToOpenXML (al, cell) = do
949− $ blocksToOpenXML opts cell
951+ es <- withParaProp (alignmentFor al) $ blocksToOpenXML opts cell
952+ if any (\e -> qName (elName e) == "p") es
953+ then return es
954+ else return $ es ++ [mknode "w:p" [] ()]
950 headers' <- mapM cellToOpenXML $ zip aligns headers
955 headers' <- mapM cellToOpenXML $ zip aligns headers
951 rows' <- mapM (mapM cellToOpenXML . zip aligns) rows
956 rows' <- mapM (mapM cellToOpenXML . zip aligns) rows
952 let borderProps = mknode "w:tcPr" []
957 let borderProps = mknode "w:tcPr" []