aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2022-09-29 10:19:38 -0700
committerJohn MacFarlane <[email protected]>2022-09-29 10:20:58 -0700
commit48d0bfc6753361d0210f142578f248bf9a887d3e (patch)
treef91ad8cd7f4765cd5400dd17050613d8972d46be /src
parent57fd3c4f81138aaaf52acb876f088611beeb8542 (diff)
Add `--list-tables` option.
[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.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/App/CommandLineOptions.hs6
-rw-r--r--src/Text/Pandoc/App/Opt.hs5
-rw-r--r--src/Text/Pandoc/App/OutputSettings.hs1
-rw-r--r--src/Text/Pandoc/Options.hs2
-rw-r--r--src/Text/Pandoc/Writers/RST.hs4
5 files changed, 16 insertions, 2 deletions
diff --git a/src/Text/Pandoc/App/CommandLineOptions.hs b/src/Text/Pandoc/App/CommandLineOptions.hs
index a25c22e28..882d94cd2 100644
--- a/src/Text/Pandoc/App/CommandLineOptions.hs
+++ b/src/Text/Pandoc/App/CommandLineOptions.hs
@@ -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 }))
diff --git a/src/Text/Pandoc/App/Opt.hs b/src/Text/Pandoc/App/Opt.hs
index 57951347d..578a507b7 100644
--- a/src/Text/Pandoc/App/Opt.hs
+++ b/src/Text/Pandoc/App/Opt.hs
@@ -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
@@ -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"
@@ -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" ->
@@ -745,6 +749,7 @@ defaultOpts = Opt
, optPdfEngineOpts = []
, optSlideLevel = Nothing
, optSetextHeaders = False
+ , optListTables = False
, optAscii = False
, optDefaultImageExtension = ""
, optExtractMedia = Nothing
diff --git a/src/Text/Pandoc/App/OutputSettings.hs b/src/Text/Pandoc/App/OutputSettings.hs
index ccdb53112..685972348 100644
--- a/src/Text/Pandoc/App/OutputSettings.hs
+++ b/src/Text/Pandoc/App/OutputSettings.hs
@@ -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
diff --git a/src/Text/Pandoc/Options.hs b/src/Text/Pandoc/Options.hs
index 92b471827..d7040a97c 100644
--- a/src/Text/Pandoc/Options.hs
+++ b/src/Text/Pandoc/Options.hs
@@ -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
@@ -347,6 +348,7 @@ instance Default WriterOptions where
, writerListings = False
, writerHighlightStyle = Just pygments
, writerSetextHeaders = False
+ , writerListTables = False
, writerEpubSubdirectory = "EPUB"
, writerEpubMetadata = Nothing
, writerEpubFonts = []
diff --git a/src/Text/Pandoc/Writers/RST.hs b/src/Text/Pandoc/Writers/RST.hs
index 08922bbd0..1745561d2 100644
--- a/src/Text/Pandoc/Writers/RST.hs
+++ b/src/Text/Pandoc/Writers/RST.hs
@@ -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
@@ -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