git.iko.soy/typeable/pandoc
on master help sign in
Docx writer: autoset table width if no column has an explicit width.
0921b82Albert Krewinkel
src/Text/Pandoc/Writers/Docx/Table.hs+11−7
@@ -1,7 +1,8 @@
1+{-# LANGUAGE LambdaCase #-}
1{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE ScopedTypeVariables #-}
3{-# LANGUAGE ScopedTypeVariables #-}
3{- |
4{- |
4−Module : Text.Pandoc.Writers.Docx
5+Module : Text.Pandoc.Writers.Docx.Table
5Copyright : Copyright (C) 2012-2021 John MacFarlane
6Copyright : Copyright (C) 2012-2021 John MacFarlane
6License : GNU GPL, version 2 or above
7License : GNU GPL, version 2 or above
7Maintainer : John MacFarlane <jgm@berkeley.edu>
8Maintainer : John MacFarlane <jgm@berkeley.edu>
@@ -87,7 +88,10 @@ tableToOpenXML blocksToOpenXML blkCapt specs thead tbody tfoot = do
87 mknode "w:tbl" []
88 mknode "w:tbl" []
88 ( mknode "w:tblPr" []
89 ( mknode "w:tblPr" []
89 ( mknode "w:tblStyle" [("w:val","Table")] () :
90 ( mknode "w:tblStyle" [("w:val","Table")] () :
91+ mknode "w:tblW" (if all (== 0) widths
92+ then [("w:type", "auto"), ("w:w", "0")]
90− mknode "w:tblW" [("w:type", "pct"), ("w:w", tshow rowwidth)] () :
93+ else [("w:type", "pct"), ("w:w", tshow rowwidth)])
94+ () :
91 mknode "w:tblLook" [("w:firstRow",if hasHeader then "1" else "0")
95 mknode "w:tblLook" [("w:firstRow",if hasHeader then "1" else "0")
92 ,("w:lastRow","0")
96 ,("w:lastRow","0")
93 ,("w:firstColumn","0")
97 ,("w:firstColumn","0")
@@ -107,8 +111,8 @@ tableToOpenXML blocksToOpenXML blkCapt specs thead tbody tfoot = do
107 )]
111 )]
108
112
109alignmentToString :: Alignment -> Text
113alignmentToString :: Alignment -> Text
110−alignmentToString alignment = case alignment of
114+alignmentToString = \case
111− AlignLeft -> "left"
115+ AlignLeft -> "left"
112− AlignRight -> "right"
116+ AlignRight -> "right"
113− AlignCenter -> "center"
117+ AlignCenter -> "center"
114− AlignDefault -> "left"
118+ AlignDefault -> "left"
test/docx/golden/table_one_row.docx

Binary file not shown.

test/docx/golden/table_with_list_cell.docx

Binary file not shown.

test/docx/golden/tables.docx

Binary file not shown.