aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbert Krewinkel <albert@zeitkraut.de>2021-04-26 18:07:01 +0200
committerAlbert Krewinkel <albert@zeitkraut.de>2021-04-27 13:27:20 +0200
commit0921b82d98b6ec7fa80ffd522c129b3828b9c00b (patch)
treeff548699d3d6a34fb4fa6356e0239edfddbfa81e
parentd0d8bb981861a5c076d1c525240791f631140f80 (diff)
downloadpandoc-0921b82d98b6ec7fa80ffd522c129b3828b9c00b.tar.gz
Docx writer: autoset table width if no column has an explicit width.
-rw-r--r--src/Text/Pandoc/Writers/Docx/Table.hs18
-rw-r--r--test/docx/golden/table_one_row.docxbin9903 -> 9904 bytes
-rw-r--r--test/docx/golden/table_with_list_cell.docxbin10212 -> 10212 bytes
-rw-r--r--test/docx/golden/tables.docxbin10238 -> 10239 bytes
4 files changed, 11 insertions, 7 deletions
diff --git a/src/Text/Pandoc/Writers/Docx/Table.hs b/src/Text/Pandoc/Writers/Docx/Table.hs
index a6b137fc4..349f3a4ce 100644
--- a/src/Text/Pandoc/Writers/Docx/Table.hs
+++ b/src/Text/Pandoc/Writers/Docx/Table.hs
@@ -1,7 +1,8 @@
+{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{- |
-Module : Text.Pandoc.Writers.Docx
+Module : Text.Pandoc.Writers.Docx.Table
Copyright : Copyright (C) 2012-2021 John MacFarlane
License : GNU GPL, version 2 or above
Maintainer : John MacFarlane <jgm@berkeley.edu>
@@ -87,7 +88,10 @@ tableToOpenXML blocksToOpenXML blkCapt specs thead tbody tfoot = do
mknode "w:tbl" []
( mknode "w:tblPr" []
( mknode "w:tblStyle" [("w:val","Table")] () :
- mknode "w:tblW" [("w:type", "pct"), ("w:w", tshow rowwidth)] () :
+ mknode "w:tblW" (if all (== 0) widths
+ then [("w:type", "auto"), ("w:w", "0")]
+ else [("w:type", "pct"), ("w:w", tshow rowwidth)])
+ () :
mknode "w:tblLook" [("w:firstRow",if hasHeader then "1" else "0")
,("w:lastRow","0")
,("w:firstColumn","0")
@@ -107,8 +111,8 @@ tableToOpenXML blocksToOpenXML blkCapt specs thead tbody tfoot = do
)]
alignmentToString :: Alignment -> Text
-alignmentToString alignment = case alignment of
- AlignLeft -> "left"
- AlignRight -> "right"
- AlignCenter -> "center"
- AlignDefault -> "left"
+alignmentToString = \case
+ AlignLeft -> "left"
+ AlignRight -> "right"
+ AlignCenter -> "center"
+ AlignDefault -> "left"
diff --git a/test/docx/golden/table_one_row.docx b/test/docx/golden/table_one_row.docx
index 6eaea2ac2..cab3fc31c 100644
--- a/test/docx/golden/table_one_row.docx
+++ b/test/docx/golden/table_one_row.docx
Binary files differ
diff --git a/test/docx/golden/table_with_list_cell.docx b/test/docx/golden/table_with_list_cell.docx
index 45a97ccaa..9238c7e20 100644
--- a/test/docx/golden/table_with_list_cell.docx
+++ b/test/docx/golden/table_with_list_cell.docx
Binary files differ
diff --git a/test/docx/golden/tables.docx b/test/docx/golden/tables.docx
index 115a16a48..6f0379def 100644
--- a/test/docx/golden/tables.docx
+++ b/test/docx/golden/tables.docx
Binary files differ