diff options
author | John MacFarlane <jgm@berkeley.edu> | 2018-10-07 18:57:25 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2018-10-07 18:57:25 -0700 |
commit | b02c25b2cafb56f9f5bbcb0edf9f957b93b4afd0 (patch) | |
tree | 293f01ceddc2745f0b7e4781f8845ad308d9086f | |
parent | 145710c4c3951b095206c59256ac0294b23ca76d (diff) | |
download | pandoc-b02c25b2cafb56f9f5bbcb0edf9f957b93b4afd0.tar.gz |
Docx writer: handle tables in table cells.
Although this is not documented in the spec, some versions of
Word require a 'w:p' element inside every table cell. Thus, we
add one when the contents of a cell do not already include one
(e.g. when a table cell contains a table).
Closes #4953.
-rw-r--r-- | src/Text/Pandoc/Writers/Docx.hs | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Writers/Docx.hs b/src/Text/Pandoc/Writers/Docx.hs index 524d20fd1..6ff38535b 100644 --- a/src/Text/Pandoc/Writers/Docx.hs +++ b/src/Text/Pandoc/Writers/Docx.hs @@ -945,8 +945,13 @@ blockToOpenXML' opts (Table caption aligns widths headers rows) = do else withParaProp (pCustomStyle "TableCaption") $ blockToOpenXML opts (Para caption) let alignmentFor al = mknode "w:jc" [("w:val",alignmentToString al)] () - let cellToOpenXML (al, cell) = withParaProp (alignmentFor al) - $ blocksToOpenXML opts cell + -- Table cells require a <w:p> element, even an empty one! + -- Not in the spec but in Word 2007, 2010. See #4953. + let cellToOpenXML (al, cell) = do + es <- withParaProp (alignmentFor al) $ blocksToOpenXML opts cell + if any (\e -> qName (elName e) == "p") es + then return es + else return $ es ++ [mknode "w:p" [] ()] headers' <- mapM cellToOpenXML $ zip aligns headers rows' <- mapM (mapM cellToOpenXML . zip aligns) rows let borderProps = mknode "w:tcPr" [] |