aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2022-08-26 15:15:38 -0700
committerJohn MacFarlane <[email protected]>2022-08-26 15:15:38 -0700
commite17c6832b12c5762c5d13c8b9de3f14b324193bd (patch)
treecb84735b91c4ba114aa4b3390a1a1edd9ac707a3
parenta5840d4f3b78687e701eef25ba4d4e9b4aa52483 (diff)
Docx writer: Indent tables in list items.
Closes #5947.
-rw-r--r--src/Text/Pandoc/Writers/Docx.hs4
-rw-r--r--src/Text/Pandoc/Writers/Docx/Table.hs7
2 files changed, 9 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Writers/Docx.hs b/src/Text/Pandoc/Writers/Docx.hs
index c596113a4..7859bc277 100644
--- a/src/Text/Pandoc/Writers/Docx.hs
+++ b/src/Text/Pandoc/Writers/Docx.hs
@@ -937,8 +937,8 @@ blockToOpenXML' opts (Table attr caption colspecs thead tbodies tfoot) = do
-- Remove extra paragraph indentation due to list items (#5947).
-- This means that tables in lists will not be indented, but it
-- avoids unwanted indentation in each cell.
- content <- local (\env -> env{ envListLevel = - 1 }) $ tableToOpenXML opts
- (blocksToOpenXML opts)
+ content <- tableToOpenXML opts
+ (local (\env -> env{ envListLevel = -1 }) . blocksToOpenXML opts)
(Grid.toTable attr caption colspecs thead tbodies tfoot)
let (tableId, _, _) = attr
wrapBookmark tableId content
diff --git a/src/Text/Pandoc/Writers/Docx/Table.hs b/src/Text/Pandoc/Writers/Docx/Table.hs
index 02fa5c63e..9b26c8b44 100644
--- a/src/Text/Pandoc/Writers/Docx/Table.hs
+++ b/src/Text/Pandoc/Writers/Docx/Table.hs
@@ -31,10 +31,12 @@ import Text.Pandoc.Class.PandocMonad (PandocMonad, translateTerm)
import Text.Pandoc.Writers.Docx.Types
( WS,
WriterState(stNextTableNum, stInTable),
+ WriterEnv(..),
setFirstPara,
pStyleM,
withParaProp,
withParaPropM )
+import Control.Monad.Reader (asks)
import Text.Pandoc.Shared ( tshow, stringify )
import Text.Pandoc.Options (WriterOptions, isEnabled)
import Text.Pandoc.Extensions (Extension(Ext_native_numbering))
@@ -97,6 +99,8 @@ tableToOpenXML opts blocksToOpenXML gridTable = do
-- 0×0400 Do not apply column banding conditional formattin
let tblLookVal = if hasHeader then (0x20 :: Int) else 0
let (gridCols, tblWattr) = tableLayout (elems colspecs)
+ listLevel <- asks envListLevel
+ let indent = (listLevel + 1) * 720
let tbl = mknode "w:tbl" []
( mknode "w:tblPr" []
( mknode "w:tblStyle" [("w:val","Table")] () :
@@ -109,6 +113,9 @@ tableToOpenXML opts blocksToOpenXML gridTable = do
,("w:noVBand","0")
,("w:val", T.pack $ printf "%04x" tblLookVal)
] () :
+ mknode "w:jc" [("w:val","start")] ()
+ : [ mknode "w:tblInd" [("w:w", tshow indent),("w:type","dxa")] ()
+ | indent > 0 ] ++
[ mknode "w:tblCaption" [("w:val", captionStr)] ()
| not (T.null captionStr) ]
)