diff options
| author | John MacFarlane <[email protected]> | 2024-10-01 08:47:29 -0700 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2024-10-01 08:47:29 -0700 |
| commit | 0d9cfc8ec0f623f7d26a867e876d6d85a94bd0e8 (patch) | |
| tree | 3420323f15b262d572ecbd03e71a9a0be9e0d44d | |
| parent | f202ae159587374079beb9dc6a1950334b618c3e (diff) | |
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.
| -rw-r--r-- | src/Text/Pandoc/Writers/RST.hs | 20 | ||||
| -rw-r--r-- | test/command/10236.md | 42 | ||||
| -rw-r--r-- | test/command/4564.md | 24 |
3 files changed, 56 insertions, 30 deletions
diff --git a/src/Text/Pandoc/Writers/RST.hs b/src/Text/Pandoc/Writers/RST.hs index 4f14030db..3f365d8a3 100644 --- a/src/Text/Pandoc/Writers/RST.hs +++ b/src/Text/Pandoc/Writers/RST.hs @@ -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 . diff --git a/test/command/10236.md b/test/command/10236.md index 9406e7a04..7b3b52231 100644 --- a/test/command/10236.md +++ b/test/command/10236.md @@ -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* +``` + diff --git a/test/command/4564.md b/test/command/4564.md index 736570a07..c808ccbd5 100644 --- a/test/command/4564.md +++ b/test/command/4564.md @@ -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. ``` |
