git.iko.soy/typeable/pandoc
on master help sign in
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.

commitbf4a164a6f832bbb8435c4021a6b019f8e1c29f7 authorJohn MacFarlane <jgm@berkeley.edu> dateFri 8 Mar 2019, 08:40 (8 years ago) parenta286ef2
2 files changed+38−22
MANUAL.txt+23−16 src/Text/Pandoc/App/CommandLineOptions.hs+15−6
MANUAL.txt+23−16
@@ -695,12 +695,17 @@ General writer options {.options}
695695
696696: Print the system default template for an output *FORMAT*. (See `-t`
697697 for a list of possible *FORMAT*s.) Templates in the user data
698− directory are ignored.
698+ directory are ignored. This option may be used with
699+ `-o`/`--output` to redirect output to a file, but
700+ `-o`/`--output` must come before `--print-default-template`
701+ on the command line.
699702
700703`--print-default-data-file=`*FILE*
701704
702705: Print a system default data file. Files in the user data directory
703− are ignored.
706+ are ignored. This option may be used with `-o`/`--output` to
707+ redirect output to a file, but `-o`/`--output` must come before
708+ `--print-default-data-file` on the command line.
704709
705710`--eol=crlf`|`lf`|`native`
706711
@@ -784,7 +789,10 @@ General writer options {.options}
784789
785790: Prints a JSON version of a highlighting style, which can
786791 be modified, saved with a `.theme` extension, and used
787− with `--highlight-style`.
792+ with `--highlight-style`. This option may be used with
793+ `-o`/`--output` to redirect output to a file, but
794+ `-o`/`--output` must come before `--print-highlight-style`
795+ on the command line.
788796
789797`--syntax-definition=`*FILE*
790798
@@ -1016,11 +1024,11 @@ Options affecting specific writers {.options}
10161024
10171025 To produce a custom `reference.docx`, first get a copy of
10181026 the default `reference.docx`: `pandoc
1019− --print-default-data-file reference.docx >
1020− custom-reference.docx`. Then open `custom-reference.docx`
1021− in Word, modify the styles as you wish, and save the file.
1022− For best results, do not make changes to this file other
1023− than modifying the styles used by pandoc:
1027+ -o custom-reference.docx --print-default-data-file reference.docx`.
1028+ Then open `custom-reference.docx` in Word, modify the
1029+ styles as you wish, and save the file. For best
1030+ results, do not make changes to this file other than
1031+ modifying the styles used by pandoc:
10241032
10251033 Paragraph styles:
10261034
@@ -1078,10 +1086,9 @@ Options affecting specific writers {.options}
10781086
10791087 To produce a custom `reference.odt`, first get a copy of
10801088 the default `reference.odt`: `pandoc
1081− --print-default-data-file reference.odt >
1082− custom-reference.odt`. Then open `custom-reference.odt` in
1083− LibreOffice, modify the styles as you wish, and save the
1084− file.
1089+ -o custom-reference.odt --print-default-data-file reference.odt`.
1090+ Then open `custom-reference.odt` in LibreOffice, modify
1091+ the styles as you wish, and save the file.
10851092
10861093 PowerPoint
10871094
@@ -1102,10 +1109,10 @@ Options affecting specific writers {.options}
11021109 `Home` menu to check.)
11031110
11041111 You can also modify the default `reference.pptx`: first run
1105− `pandoc --print-default-data-file reference.pptx >
1106− custom-reference.pptx`, and then modify
1107− `custom-reference.pptx` in MS PowerPoint (pandoc will use the
1108− first four layout slides, as mentioned above).
1112+ `pandoc -o custom-reference.pptx --print-default-data-file
1113+ reference.pptx`, and then modify `custom-reference.pptx`
1114+ in MS PowerPoint (pandoc will use the first four layout
1115+ slides, as mentioned above).
11091116
11101117`--epub-cover-image=`*FILE*
11111118
src/Text/Pandoc/App/CommandLineOptions.hs+15−6
@@ -786,7 +786,10 @@ options =
786786
787787 , Option "D" ["print-default-template"]
788788 (ReqArg
789− (\arg _ -> do
789+ (\arg opt -> do
790+ let write = case optOutputFile opt of
791+ Just f -> UTF8.writeFile f
792+ Nothing -> UTF8.hPutStr stdout
790793 templ <- runIO $ do
791794 setUserDataDir Nothing
792795 getDefaultTemplate arg
@@ -794,7 +797,7 @@ options =
794797 Right "" -> -- e.g. for docx, odt, json:
795798 E.throwIO $ PandocCouldNotFindDataFileError
796799 ("templates/default." ++ arg)
797− Right t -> UTF8.hPutStr stdout t
800+ Right t -> write t
798801 Left e -> E.throwIO e
799802 exitSuccess)
800803 "FORMAT")
@@ -802,18 +805,24 @@ options =
802805
803806 , Option "" ["print-default-data-file"]
804807 (ReqArg
805− (\arg _ -> do
808+ (\arg opt -> do
809+ let write = case optOutputFile opt of
810+ Just f -> BS.writeFile f
811+ Nothing -> BS.hPutStr stdout
806812 runIOorExplode $
807− readDefaultDataFile arg >>= liftIO . BS.hPutStr stdout
813+ readDefaultDataFile arg >>= liftIO . write
808814 exitSuccess)
809815 "FILE")
810816 "" -- "Print default data file"
811817
812818 , Option "" ["print-highlight-style"]
813819 (ReqArg
814− (\arg _ -> do
820+ (\arg opt -> do
821+ let write = case optOutputFile opt of
822+ Just f -> B.writeFile f
823+ Nothing -> B.putStr
815824 sty <- fromMaybe pygments <$> lookupHighlightStyle arg
816− B.putStr $ encodePretty'
825+ write $ encodePretty'
817826 defConfig{confIndent = Spaces 4
818827 ,confCompare = keyOrder
819828 (map T.pack