aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTuongNM <[email protected]>2025-10-14 19:07:02 +0200
committerGitHub <[email protected]>2025-10-14 19:07:02 +0200
commit80ccc78a522845e5c35c6f65845a4315ba699924 (patch)
tree0da187355a9112ee41bc04461e93bf7e8a5c1a19 /src
parentd81ee85952400ef62b83146ed695a5ea113d120d (diff)
RST writer: Don't use simple tables with RowSpans (#11214)
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Writers/RST.hs17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/Text/Pandoc/Writers/RST.hs b/src/Text/Pandoc/Writers/RST.hs
index cfae285ba..7a6bc29b9 100644
--- a/src/Text/Pandoc/Writers/RST.hs
+++ b/src/Text/Pandoc/Writers/RST.hs
@@ -328,7 +328,7 @@ blockToRST (CodeBlock (_,classes,kvs) str) = do
blockToRST (BlockQuote blocks) = do
contents <- blockListToRST blocks
return $ nest 3 contents <> blankline
-blockToRST (Table _attrs blkCapt specs thead tbody tfoot) = do
+blockToRST (Table _attrs blkCapt specs thead@(TableHead _ theadRows) tbody tfoot@(TableFoot _ tfootRows)) = do
let (caption, aligns, widths, headers, rows) =
toLegacyTable blkCapt specs thead tbody tfoot
caption' <- inlineListToRST caption
@@ -341,7 +341,9 @@ blockToRST (Table _attrs blkCapt specs thead tbody tfoot) = do
opts <- gets stOptions
let specs' = map (\(_,width) -> (AlignDefault, width)) specs
renderGrid = gridTable opts blocksToDoc specs' thead tbody tfoot
- isSimple = all (== 0) widths && length widths > 1
+ rowHasRowSpan (Row _ cells) = any cellHasRowSpan cells
+ cellHasRowSpan (Cell _ _ rowSpan _ _) = rowSpan > 1
+ isSimple = all (== 0) widths && length widths > 1 && not (any rowHasRowSpan $ theadRows ++ tableBodiesToRows tbody ++ tfootRows)
renderSimple = do
tbl' <- simpleTable opts blocksToDoc thead tbody tfoot
if offset tbl' > writerColumns opts
@@ -926,7 +928,7 @@ simpleTable opts blocksToDoc (TableHead _ headers) tbody (TableFoot _ footers) =
headerDocs <- if all isEmptyRow headers
then return []
else fixEmpties <$> mapM rowToDoc headers
- rowDocs <- fixEmpties <$> mapM rowToDoc ((concatMap tableBodyToRows tbody) ++ footers)
+ rowDocs <- fixEmpties <$> mapM rowToDoc ((tableBodiesToRows tbody) ++ footers)
let numChars = maybe 0 maximum . NE.nonEmpty . map (offset . fst)
let colWidths = map numChars $ transpose (headerDocs ++ rowDocs)
let hline = nowrap $ hsep (map (\n -> literal (T.replicate n "=")) colWidths)
@@ -953,8 +955,6 @@ simpleTable opts blocksToDoc (TableHead _ headers) tbody (TableFoot _ footers) =
cellToDocs (Cell _ _ _ colSpan blocks) = applyColSpan colSpan <$> (blocksToDoc opts) blocks
- tableBodyToRows (TableBody _ _ headerRows bodyRows) = headerRows ++ bodyRows
-
applyColSpan col@(ColSpan colSpan) doc
| colSpan > 1 =
-- Fill up columns for the col spans by adding empty docs without a ColSpan.
@@ -991,3 +991,10 @@ simpleTable opts blocksToDoc (TableHead _ headers) tbody (TableFoot _ footers) =
then colWidthsSum + colWidthsLength - 1
else colWidthsSum
in literal $ T.replicate dashLength "-"
+
+-- | Concatenates the header and body Rows of a List of TableBody into a flat
+-- List of Rows.
+tableBodiesToRows :: [TableBody] -> [Row]
+tableBodiesToRows = concatMap tableBodyToRows
+ where
+ tableBodyToRows (TableBody _ _ headerRows bodyRows) = headerRows ++ bodyRows