Skip to content

Commit

Permalink
Add --list-tables option.
Browse files Browse the repository at this point in the history
[API change] Add writerListTables to WriterOptions.

RST writer: Remove sensitivity to "list-table" class in table attributes.
Instead, just check `writerListTables` in writer options.

See #4564.
  • Loading branch information
jgm committed Sep 29, 2022
1 parent 57fd3c4 commit 48d0bfc
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 4 deletions.
8 changes: 8 additions & 0 deletions MANUAL.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,10 @@ header when requesting a document from a URL:

: *Deprecated synonym for `--markdown-headings=atx`.*

`--list-tables`

: Render tables as list tables in RST output.

`--top-level-division=default`|`section`|`chapter`|`part`

: Treat top-level headings as the given division type in
Expand Down Expand Up @@ -1900,6 +1904,10 @@ To include the built-in citeproc filter, use either `citeproc` or
| ``` | ``` |
+----------------------------------+-----------------------------------+
| ``` | ``` yaml |
| --list-tables | list-tables: true |
| ``` | ``` |
+----------------------------------+-----------------------------------+
| ``` | ``` yaml |
| --top-level-division chapter | top-level-division: chapter |
| ``` | ``` |
+----------------------------------+-----------------------------------+
Expand Down
6 changes: 6 additions & 0 deletions src/Text/Pandoc/App/CommandLineOptions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,12 @@ options =
"setext|atx")
""

, Option "" ["list-tables"]
(NoArg
(\opt -> do
return opt { optListTables = True } ))
"" -- "Use list tables for RST"

, Option "" ["listings"]
(NoArg
(\opt -> return opt { optListings = True }))
Expand Down
5 changes: 5 additions & 0 deletions src/Text/Pandoc/App/Opt.hs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ data Opt = Opt
, optPdfEngineOpts :: [String] -- ^ Flags to pass to the engine
, optSlideLevel :: Maybe Int -- ^ Header level that creates slides
, optSetextHeaders :: Bool -- ^ Use atx headers for markdown level 1-2
, optListTables :: Bool -- ^ Use list tables for RST
, optAscii :: Bool -- ^ Prefer ascii output
, optDefaultImageExtension :: Text -- ^ Default image extension
, optExtractMedia :: Maybe FilePath -- ^ Path to extract embedded media
Expand Down Expand Up @@ -215,6 +216,7 @@ instance FromJSON Opt where
<*> o .:? "pdf-engine-opts" .!= optPdfEngineOpts defaultOpts
<*> o .:? "slide-level"
<*> o .:? "setext-headers" .!= optSetextHeaders defaultOpts
<*> o .:? "list-tables" .!= optListTables defaultOpts
<*> o .:? "ascii" .!= optAscii defaultOpts
<*> o .:? "default-image-extension" .!= optDefaultImageExtension defaultOpts
<*> o .:? "extract-media"
Expand Down Expand Up @@ -609,6 +611,8 @@ doOpt (k,v) = do
"atx" -> o{ optSetextHeaders = False }
"setext" -> o{ optSetextHeaders = True }
_ -> o)
"list-tables" ->
parseJSON v >>= \x -> return (\o -> o{ optListTables = x })
"ascii" ->
parseJSON v >>= \x -> return (\o -> o{ optAscii = x })
"default-image-extension" ->
Expand Down Expand Up @@ -745,6 +749,7 @@ defaultOpts = Opt
, optPdfEngineOpts = []
, optSlideLevel = Nothing
, optSetextHeaders = False
, optListTables = False
, optAscii = False
, optDefaultImageExtension = ""
, optExtractMedia = Nothing
Expand Down
1 change: 1 addition & 0 deletions src/Text/Pandoc/App/OutputSettings.hs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ optToOutputSettings opts = do
, writerSlideLevel = optSlideLevel opts
, writerHighlightStyle = hlStyle
, writerSetextHeaders = optSetextHeaders opts
, writerListTables = optListTables opts
, writerEpubSubdirectory = T.pack $ optEpubSubdirectory opts
, writerEpubMetadata = epubMetadata
, writerEpubFonts = optEpubFonts opts
Expand Down
2 changes: 2 additions & 0 deletions src/Text/Pandoc/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ data WriterOptions = WriterOptions
, writerHighlightStyle :: Maybe Style -- ^ Style to use for highlighting
-- (Nothing = no highlighting)
, writerSetextHeaders :: Bool -- ^ Use setext headers for levels 1-2 in markdown
, writerListTables :: Bool -- ^ Use list tables for RST tables
, writerEpubSubdirectory :: Text -- ^ Subdir for epub in OCF
, writerEpubMetadata :: Maybe Text -- ^ Metadata to include in EPUB
, writerEpubFonts :: [FilePath] -- ^ Paths to fonts to embed
Expand Down Expand Up @@ -347,6 +348,7 @@ instance Default WriterOptions where
, writerListings = False
, writerHighlightStyle = Just pygments
, writerSetextHeaders = False
, writerListTables = False
, writerEpubSubdirectory = "EPUB"
, writerEpubMetadata = Nothing
, writerEpubFonts = []
Expand Down
4 changes: 2 additions & 2 deletions src/Text/Pandoc/Writers/RST.hs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,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 tbody tfoot) = do
let (caption, aligns, widths, headers, rows) = toLegacyTable blkCapt specs thead tbody tfoot
caption' <- inlineListToRST caption
let blocksToDoc opts bs = do
Expand All @@ -330,7 +330,7 @@ blockToRST (Table attrs blkCapt specs thead tbody tfoot) = do
if offset tbl' > writerColumns opts
then renderGrid
else return tbl'
isList = any ("list-table" ==) $ (\(_, classes, _) -> classes) attrs
isList = writerListTables opts
renderList = tableToRSTList caption (map (const AlignDefault) aligns)
widths headers rows
rendered
Expand Down
4 changes: 2 additions & 2 deletions test/command/4564.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
```
% pandoc -f native -t rst
% pandoc -f native -t rst --list-tables
[BlockQuote
[Table ("",["list-table"],[]) (Caption Nothing
[Table ("",[],[]) (Caption Nothing
[])
[(AlignDefault,ColWidth 0.1527777777777778)
,(AlignDefault,ColWidth 0.1388888888888889)
Expand Down

0 comments on commit 48d0bfc

Please sign in to comment.