aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2024-09-27 09:13:42 -0700
committerJohn MacFarlane <[email protected]>2024-09-27 09:15:23 -0700
commit9a3aed9cee0dd17ccb897b7c47cdf97b62d0d68a (patch)
treeeb8fbc47920927b5029de39e4aae22690ee8d9cb /src
parentf672706c6c44b606a44a2393aa18007cc81d7380 (diff)
RST writer: fix two issues with list tables.
- Fix alignment of list items corresponding to cells. - Don't enclose the list table in a `.. table::`; this leads to doubled captions. Closes #10226. Closes #10227. Modified test output for #4564.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Writers/RST.hs20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/Text/Pandoc/Writers/RST.hs b/src/Text/Pandoc/Writers/RST.hs
index 08ea0657c..237a467b7 100644
--- a/src/Text/Pandoc/Writers/RST.hs
+++ b/src/Text/Pandoc/Writers/RST.hs
@@ -351,7 +351,7 @@ blockToRST (Table _attrs blkCapt specs thead tbody tfoot) = do
| otherwise = renderGrid
tbl <- rendered
return $ blankline $$
- (if null caption
+ (if null caption || isList
then tbl
else (".. table:: " <> caption') $$ blankline $$ nest 3 tbl) $$
blankline
@@ -547,18 +547,18 @@ tableToRSTList caption _ propWidths headers rows = do
toColumns :: Int -> Double -> Int
toColumns t p = round (p * fromIntegral t)
listTableContent :: PandocMonad m => [[[Block]]] -> RST m (Doc Text)
- listTableContent = joinTable joinDocsM joinDocsM .
+ listTableContent = joinTable (joinDocsM '-') (joinDocsM '*') .
mapTable blockListToRST
-- joinDocsM adapts joinDocs in order to work in the `RST m` monad
- joinDocsM :: PandocMonad m => [RST m (Doc Text)] -> RST m (Doc Text)
- joinDocsM = fmap joinDocs . sequence
+ joinDocsM :: PandocMonad m
+ => Char -> [RST m (Doc Text)] -> RST m (Doc Text)
+ joinDocsM c = fmap (joinDocs c) . sequence
-- joinDocs will be used to join cells and to join rows
- joinDocs :: [Doc Text] -> Doc Text
- joinDocs items = blankline $$
- (chomp . vcat . map formatItem) items $$
- blankline
- formatItem :: Doc Text -> Doc Text
- formatItem i = hang 3 "- " (i <> cr)
+ joinDocs :: Char -> [Doc Text] -> Doc Text
+ joinDocs c items = (chomp . vcat . map (formatItem c)) items $$
+ blankline
+ formatItem :: Char -> Doc Text -> Doc Text
+ formatItem c i = hang 2 (text [c, ' ']) (i <> cr)
-- apply a function to all table cells changing their type
mapTable :: (a -> b) -> [[a]] -> [[b]]
mapTable = map . map