Skip to content

Commit

Permalink
Writers.Shared: Improve toLegacyTable.
Browse files Browse the repository at this point in the history
Closes #7683.
(PR #7684)
  • Loading branch information
despresc authored Nov 12, 2021
1 parent ebf7f78 commit abdfefe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Text/Pandoc/Writers/Shared.hs
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ toLegacyTable (Caption _ cbody) specs thead tbodies tfoot
= let (h, w, cBody) = getComponents c
cRowPieces = cBody : replicate (w - 1) mempty
cPendingPieces = replicate w $ replicate (h - 1) mempty
pendingPieces' = dropWhile null pendingPieces
pendingPieces' = drop w pendingPieces
(pendingPieces'', rowPieces) = placeCutCells pendingPieces' cells'
in (cPendingPieces <> pendingPieces'', cRowPieces <> rowPieces)
| otherwise = ([], [])
Expand Down
16 changes: 16 additions & 0 deletions test/Tests/Shared.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ testLegacyTable :: [TestTree]
testLegacyTable =
[ testCase "decomposes a table with head" $ gen1 @?= expect1
, testCase "decomposes a table without head" $ gen2 @?= expect2
, testCase "decomposes the table from issue 7683" $ gen3 @?= expect3
]
where
pln = toList . plain . str
Expand Down Expand Up @@ -110,3 +111,18 @@ testLegacyTable =
,[pln "j", mempty, mempty]]
)
gen2 = toLegacyTable emptyCaption spec1 (th []) [body1] (tf footRows1)

spec3 = replicate 4 (AlignDefault, ColWidthDefault)
body3 = tb 0
[]
[[cl "a" 2 1, cl "b" 1 2, cl "c" 2 1]
,[cl "d" 1 1, cl "e" 1 1]
]
expect3 = ( []
, replicate 4 AlignDefault
, replicate 4 0
, []
, [[pln "a", pln "b", mempty, pln "c"]
,[mempty, pln "d", pln "e", mempty]]
)
gen3 = toLegacyTable emptyCaption spec3 (th []) [body3] (tf [])

0 comments on commit abdfefe

Please sign in to comment.