Skip to content

Commit

Permalink
Docx writer: separate adjacent tables.
Browse files Browse the repository at this point in the history
Word combines adjacent tables, so to prevent this we insert
an empty paragraph between two adjacent tables.

Closes #4315.
  • Loading branch information
jgm committed Aug 24, 2020
1 parent 49e810b commit 93e3d46
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Text/Pandoc/Writers/Docx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,15 @@ writeOpenXML opts (Pandoc meta blocks) = do

-- | Convert a list of Pandoc blocks to OpenXML.
blocksToOpenXML :: (PandocMonad m) => WriterOptions -> [Block] -> WS m [Element]
blocksToOpenXML opts bls = concat `fmap` mapM (blockToOpenXML opts) bls
blocksToOpenXML opts = fmap concat . mapM (blockToOpenXML opts) . separateTables

-- Word combines adjacent tables unless you put an empty paragraph between
-- them. See #4315.
separateTables :: [Block] -> [Block]
separateTables [] = []
separateTables (x@Table{}:y@Table{}:zs) =
x : RawBlock (Format "openxml") "<w:p />" : separateTables (y:zs)
separateTables (x:xs) = x : separateTables xs

pStyleM :: (PandocMonad m) => ParaStyleName -> WS m XML.Element
pStyleM styleName = do
Expand Down
Binary file modified test/docx/golden/tables.docx
Binary file not shown.

0 comments on commit 93e3d46

Please sign in to comment.