aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2019-03-08 08:40:31 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2019-03-08 08:44:45 -0800
commitbf4a164a6f832bbb8435c4021a6b019f8e1c29f7 (patch)
treef700ced17976608df8cb7bf679b844a5817dfc42
parenta286ef2eb5e0afd3163f7214cdbbba430a61d031 (diff)
downloadpandoc-bf4a164a6f832bbb8435c4021a6b019f8e1c29f7.tar.gz
Allow -o/--output to be used with --print-*.
`--print-default-data-file` `--print-highlighting-style` `--print-default-template` Note that `-o` must occur BEFORE the `--print*` command on the command line (this is documented). Closes #5357.
-rw-r--r--MANUAL.txt39
-rw-r--r--src/Text/Pandoc/App/CommandLineOptions.hs21
2 files changed, 38 insertions, 22 deletions
diff --git a/MANUAL.txt b/MANUAL.txt
index df5dccd5e..08d3363e9 100644
--- a/MANUAL.txt
+++ b/MANUAL.txt
@@ -695,12 +695,17 @@ General writer options {.options}
: Print the system default template for an output *FORMAT*. (See `-t`
for a list of possible *FORMAT*s.) Templates in the user data
- directory are ignored.
+ directory are ignored. This option may be used with
+ `-o`/`--output` to redirect output to a file, but
+ `-o`/`--output` must come before `--print-default-template`
+ on the command line.
`--print-default-data-file=`*FILE*
: Print a system default data file. Files in the user data directory
- are ignored.
+ are ignored. This option may be used with `-o`/`--output` to
+ redirect output to a file, but `-o`/`--output` must come before
+ `--print-default-data-file` on the command line.
`--eol=crlf`|`lf`|`native`
@@ -784,7 +789,10 @@ General writer options {.options}
: Prints a JSON version of a highlighting style, which can
be modified, saved with a `.theme` extension, and used
- with `--highlight-style`.
+ with `--highlight-style`. This option may be used with
+ `-o`/`--output` to redirect output to a file, but
+ `-o`/`--output` must come before `--print-highlight-style`
+ on the command line.
`--syntax-definition=`*FILE*
@@ -1016,11 +1024,11 @@ Options affecting specific writers {.options}
To produce a custom `reference.docx`, first get a copy of
the default `reference.docx`: `pandoc
- --print-default-data-file reference.docx >
- custom-reference.docx`. Then open `custom-reference.docx`
- in Word, modify the styles as you wish, and save the file.
- For best results, do not make changes to this file other
- than modifying the styles used by pandoc:
+ -o custom-reference.docx --print-default-data-file reference.docx`.
+ Then open `custom-reference.docx` in Word, modify the
+ styles as you wish, and save the file. For best
+ results, do not make changes to this file other than
+ modifying the styles used by pandoc:
Paragraph styles:
@@ -1078,10 +1086,9 @@ Options affecting specific writers {.options}
To produce a custom `reference.odt`, first get a copy of
the default `reference.odt`: `pandoc
- --print-default-data-file reference.odt >
- custom-reference.odt`. Then open `custom-reference.odt` in
- LibreOffice, modify the styles as you wish, and save the
- file.
+ -o custom-reference.odt --print-default-data-file reference.odt`.
+ Then open `custom-reference.odt` in LibreOffice, modify
+ the styles as you wish, and save the file.
PowerPoint
@@ -1102,10 +1109,10 @@ Options affecting specific writers {.options}
`Home` menu to check.)
You can also modify the default `reference.pptx`: first run
- `pandoc --print-default-data-file reference.pptx >
- custom-reference.pptx`, and then modify
- `custom-reference.pptx` in MS PowerPoint (pandoc will use the
- first four layout slides, as mentioned above).
+ `pandoc -o custom-reference.pptx --print-default-data-file
+ reference.pptx`, and then modify `custom-reference.pptx`
+ in MS PowerPoint (pandoc will use the first four layout
+ slides, as mentioned above).
`--epub-cover-image=`*FILE*
diff --git a/src/Text/Pandoc/App/CommandLineOptions.hs b/src/Text/Pandoc/App/CommandLineOptions.hs
index 4253620f7..14f665aa9 100644
--- a/src/Text/Pandoc/App/CommandLineOptions.hs
+++ b/src/Text/Pandoc/App/CommandLineOptions.hs
@@ -786,7 +786,10 @@ options =
, Option "D" ["print-default-template"]
(ReqArg
- (\arg _ -> do
+ (\arg opt -> do
+ let write = case optOutputFile opt of
+ Just f -> UTF8.writeFile f
+ Nothing -> UTF8.hPutStr stdout
templ <- runIO $ do
setUserDataDir Nothing
getDefaultTemplate arg
@@ -794,7 +797,7 @@ options =
Right "" -> -- e.g. for docx, odt, json:
E.throwIO $ PandocCouldNotFindDataFileError
("templates/default." ++ arg)
- Right t -> UTF8.hPutStr stdout t
+ Right t -> write t
Left e -> E.throwIO e
exitSuccess)
"FORMAT")
@@ -802,18 +805,24 @@ options =
, Option "" ["print-default-data-file"]
(ReqArg
- (\arg _ -> do
+ (\arg opt -> do
+ let write = case optOutputFile opt of
+ Just f -> BS.writeFile f
+ Nothing -> BS.hPutStr stdout
runIOorExplode $
- readDefaultDataFile arg >>= liftIO . BS.hPutStr stdout
+ readDefaultDataFile arg >>= liftIO . write
exitSuccess)
"FILE")
"" -- "Print default data file"
, Option "" ["print-highlight-style"]
(ReqArg
- (\arg _ -> do
+ (\arg opt -> do
+ let write = case optOutputFile opt of
+ Just f -> B.writeFile f
+ Nothing -> B.putStr
sty <- fromMaybe pygments <$> lookupHighlightStyle arg
- B.putStr $ encodePretty'
+ write $ encodePretty'
defConfig{confIndent = Spaces 4
,confCompare = keyOrder
(map T.pack