From 0921b82d98b6ec7fa80ffd522c129b3828b9c00b Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Mon, 26 Apr 2021 18:07:01 +0200 Subject: Docx writer: autoset table width if no column has an explicit width. --- src/Text/Pandoc/Writers/Docx/Table.hs | 18 +++++++++++------- test/docx/golden/table_one_row.docx | Bin 9903 -> 9904 bytes test/docx/golden/table_with_list_cell.docx | Bin 10212 -> 10212 bytes test/docx/golden/tables.docx | Bin 10238 -> 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 @@ -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 Binary files a/test/docx/golden/table_one_row.docx and b/test/docx/golden/table_one_row.docx 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 Binary files a/test/docx/golden/table_with_list_cell.docx and b/test/docx/golden/table_with_list_cell.docx differ diff --git a/test/docx/golden/tables.docx b/test/docx/golden/tables.docx index 115a16a48..6f0379def 100644 Binary files a/test/docx/golden/tables.docx and b/test/docx/golden/tables.docx differ -- cgit v1.2.3