git.iko.soy/typeable/pandoc
on master help sign in
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.

commit55f9b59af181f52f20f3e9eb8f9df3046d3cb536 authorJohn MacFarlane <jgm@berkeley.edu> dateMon 28 Dec 2020, 14:41 (6 years ago) parenta7a162e
1 file changed+6−4
src/Text/Pandoc/Writers/Docx.hs+6−4
src/Text/Pandoc/Writers/Docx.hs+6−4
@@ -1011,12 +1011,14 @@ blockToOpenXML' opts (Table _ blkCapt specs thead tbody tfoot) = do
10111011 $ blockToOpenXML opts (Para caption)
10121012 let alignmentFor al = mknode "w:jc" [("w:val",alignmentToString al)] ()
10131013 -- Table cells require a <w:p> element, even an empty one!
1014− -- Not in the spec but in Word 2007, 2010. See #4953.
1014+ -- Not in the spec but in Word 2007, 2010. See #4953. And
1015+ -- apparently the last element must be a <w:p>, see #6983.
10151016 let cellToOpenXML (al, cell) = do
10161017 es <- withParaProp (alignmentFor al) $ blocksToOpenXML opts cell
1017− return $ if any (\e -> qName (elName e) == "p") (onlyElems es)
1018− then es
1019− else es ++ [Elem $ mknode "w:p" [] ()]
1018+ return $
1019+ case reverse (onlyElems es) of
1020+ e:_ | qName (elName e) == "p" -> es
1021+ _ -> es ++ [Elem $ mknode "w:p" [] ()]
10201022 headers' <- mapM cellToOpenXML $ zip aligns headers
10211023 rows' <- mapM (mapM cellToOpenXML . zip aligns) rows
10221024 let borderProps = Elem $ mknode "w:tcPr" []