Skip to content

Commit

Permalink
Docx writer: omit jc attribute on table cells with AlignDefault.
Browse files Browse the repository at this point in the history
Closes #5662.
  • Loading branch information
jgm committed Jun 2, 2024
1 parent 1992913 commit 39c549c
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/Text/Pandoc/Writers/Docx/Table.hs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 159,7 @@ alignmentToString = \case
AlignLeft -> "left"
AlignRight -> "right"
AlignCenter -> "center"
AlignDefault -> "left"
AlignDefault -> ""

tableLayout :: [ColSpec] -> ([Element], [(Text, Text)])
tableLayout specs =
Expand Down Expand Up @@ -253,7 253,7 @@ ooxmlCellToOpenXML blocksToOpenXML = \case
, mknode "w:p" [] [mknode "w:pPr" [] ()]]
OOXMLCell _attr align rowspan (ColSpan colspan) contents -> do
compactStyle <- pStyleM "Compact"
es <- withParaProp (alignmentFor align) $ blocksToOpenXML contents
es <- maybe id withParaProp (alignmentFor align) $ blocksToOpenXML contents
-- Table cells require a <w:p> element, even an empty one!
-- Not in the spec but in Word 2007, 2010. See #4953. And
-- apparently the last element must be a <w:p>, see #6983.
Expand All @@ -271,5 271,6 @@ ooxmlCellToOpenXML blocksToOpenXML = \case
e:_ | qName (elName e) == "p" -> es
_ -> es [Elem $ mknode "w:p" [] ()]

alignmentFor :: Alignment -> Element
alignmentFor al = mknode "w:jc" [("w:val",alignmentToString al)] ()
alignmentFor :: Alignment -> Maybe Element
alignmentFor AlignDefault = Nothing
alignmentFor al = Just $ mknode "w:jc" [("w:val",alignmentToString al)] ()
Binary file modified test/docx/golden/table_one_row.docx
Binary file not shown.
Binary file modified test/docx/golden/table_with_list_cell.docx
Binary file not shown.
Binary file modified test/docx/golden/tables-default-widths.docx
Binary file not shown.
Binary file modified test/docx/golden/tables.docx
Binary file not shown.
Binary file modified test/docx/golden/tables_separated_with_rawblock.docx
Binary file not shown.

0 comments on commit 39c549c

Please sign in to comment.