mirror of
https://github.com/jgm/pandoc.git
synced 2026-09-24 15:44:59 +08:00
Amend the fix to #10236 to handle list tables.
With this patch, we also reuse bullet list code for list tables, which simplifies the code.
This commit is contained in:
@@ -567,24 +567,8 @@ 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 '*') .
|
||||
mapTable blockListToRST
|
||||
-- joinDocsM adapts joinDocs in order to work in the `RST m` monad
|
||||
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 :: 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
|
||||
-- function hor to join cells and function ver to join rows
|
||||
joinTable :: ([a] -> a) -> ([a] -> a) -> [[a]] -> a
|
||||
joinTable hor ver = ver . map hor
|
||||
listTableContent = fmap vcat .
|
||||
mapM (fmap (hang 2 (text "* ") . vcat) . mapM bulletListItemToRST)
|
||||
|
||||
transformInlines :: [Inline] -> [Inline]
|
||||
transformInlines = insertBS .
|
||||
|
||||
@@ -36,3 +36,45 @@
|
||||
|
||||
test
|
||||
```
|
||||
|
||||
```
|
||||
% pandoc -f native -t rst --list-tables
|
||||
[ Table
|
||||
( "" , [] , [] )
|
||||
(Caption Nothing [])
|
||||
[ ( AlignDefault , ColWidth 0.26 ) ]
|
||||
(TableHead ( "" , [] , [] ) [])
|
||||
[ TableBody
|
||||
( "" , [] , [] )
|
||||
(RowHeadColumns 0)
|
||||
[]
|
||||
[ Row
|
||||
( "" , [] , [] )
|
||||
[ Cell
|
||||
( "" , [] , [] )
|
||||
AlignDefault
|
||||
(RowSpan 1)
|
||||
(ColSpan 1)
|
||||
[ BlockQuote
|
||||
[ Para [ Emph [ Str "Level" , Space , Str "0:" ] ]
|
||||
, Para
|
||||
[ Emph [ Str "Incomplete" , Space , Str "process" ]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
(TableFoot ( "" , [] , [] ) [])
|
||||
]
|
||||
^D
|
||||
.. list-table::
|
||||
:widths: 19
|
||||
|
||||
* - ..
|
||||
|
||||
*Level 0:*
|
||||
|
||||
*Incomplete process*
|
||||
```
|
||||
|
||||
|
||||
+12
-12
@@ -43,16 +43,16 @@
|
||||
:widths: 11 10 12 27
|
||||
:header-rows: 1
|
||||
|
||||
* - Centered Header
|
||||
- Left Aligned
|
||||
- Right Aligned
|
||||
- Default aligned
|
||||
* - First
|
||||
-
|
||||
- 12.0
|
||||
- Example of a row that spans multiple lines.
|
||||
* - Second
|
||||
- row
|
||||
- 5.0
|
||||
- Here’s another one. Note the blank line between rows.
|
||||
* - Centered Header
|
||||
- Left Aligned
|
||||
- Right Aligned
|
||||
- Default aligned
|
||||
* - First
|
||||
-
|
||||
- 12.0
|
||||
- Example of a row that spans multiple lines.
|
||||
* - Second
|
||||
- row
|
||||
- 5.0
|
||||
- Here’s another one. Note the blank line between rows.
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user