aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2020-12-28 14:41:28 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2020-12-28 14:41:28 -0800
commit55f9b59af181f52f20f3e9eb8f9df3046d3cb536 (patch)
tree5039303f02b750fae5738603c7d7d4f722c616ef
parenta7a162ea556c0a17062a4784995c7bb42fd88d77 (diff)
downloadpandoc-55f9b59af181f52f20f3e9eb8f9df3046d3cb536.tar.gz
Docx writer: fix nested tables with captions.
Previously we got unreadable content, because docx seems to want a `<w:p>` element (even an empty one) at the end of every table cell. Closes #6983.
-rw-r--r--src/Text/Pandoc/Writers/Docx.hs10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/Text/Pandoc/Writers/Docx.hs b/src/Text/Pandoc/Writers/Docx.hs
index 0174a8501..13c4edb3c 100644
--- a/src/Text/Pandoc/Writers/Docx.hs
+++ b/src/Text/Pandoc/Writers/Docx.hs
@@ -1011,12 +1011,14 @@ blockToOpenXML' opts (Table _ blkCapt specs thead tbody tfoot) = do
$ blockToOpenXML opts (Para caption)
let alignmentFor al = mknode "w:jc" [("w:val",alignmentToString al)] ()
-- Table cells require a <w:p> element, even an empty one!
- -- Not in the spec but in Word 2007, 2010. See #4953.
+ -- Not in the spec but in Word 2007, 2010. See #4953. And
+ -- apparently the last element must be a <w:p>, see #6983.
let cellToOpenXML (al, cell) = do
es <- withParaProp (alignmentFor al) $ blocksToOpenXML opts cell
- return $ if any (\e -> qName (elName e) == "p") (onlyElems es)
- then es
- else es ++ [Elem $ mknode "w:p" [] ()]
+ return $
+ case reverse (onlyElems es) of
+ e:_ | qName (elName e) == "p" -> es
+ _ -> es ++ [Elem $ mknode "w:p" [] ()]
headers' <- mapM cellToOpenXML $ zip aligns headers
rows' <- mapM (mapM cellToOpenXML . zip aligns) rows
let borderProps = Elem $ mknode "w:tcPr" []