git.iko.soy/typeable/pandoc
on master help sign in
Change behavior with binary format output to stdout.
61cf3afJohn MacFarlane
MANUAL.txt+4−4
@@ -110,8 +110,8 @@ If no *input-file* is specified, input is read from *stdin*.
110Otherwise, the *input-files* are concatenated (with a blank
110Otherwise, the *input-files* are concatenated (with a blank
111line between each) and used as input. Output goes to *stdout* by
111line between each) and used as input. Output goes to *stdout* by
112default (though output to *stdout* is disabled for the `odt`, `docx`,
112default (though output to *stdout* is disabled for the `odt`, `docx`,
113+`epub2`, and `epub3` output formats, unless it is forced using
113−`epub2`, and `epub3` output formats). For output to a file, use the
114+`-o -`). For output to a file, use the `-o` option:
114−`-o` option:
115
115
116 pandoc -o output.html input.txt
116 pandoc -o output.html input.txt
117
117
@@ -328,8 +328,8 @@ General options
328`-o` *FILE*, `--output=`*FILE*
328`-o` *FILE*, `--output=`*FILE*
329
329
330: Write output to *FILE* instead of *stdout*. If *FILE* is
330: Write output to *FILE* instead of *stdout*. If *FILE* is
331− `-`, output will go to *stdout*. (Exception: if the output
331+ `-`, output will go to *stdout*, even if a non-textual format
332− format is `odt`, `docx`, `epub`, or `epub3`, output to stdout is disabled.)
332+ (`docx`, `odt`, `epub2`, `epub3`) is specified.
333
333
334`--data-dir=`*DIRECTORY*
334`--data-dir=`*DIRECTORY*
335
335
src/Text/Pandoc/App.hs+12−19
@@ -91,10 +91,6 @@ import Text.Pandoc.Shared (headerShift, isURI, openURL,
91import qualified Text.Pandoc.UTF8 as UTF8
91import qualified Text.Pandoc.UTF8 as UTF8
92import Text.Pandoc.XML (toEntities)
92import Text.Pandoc.XML (toEntities)
93import Text.Printf
93import Text.Printf
94−#ifndef _WINDOWS
95−import System.Posix.IO (stdOutput)
96−import System.Posix.Terminal (queryTerminal)
97−#endif
98
94
99data LineEnding = LF | CRLF | Native deriving (Show, Generic)
95data LineEnding = LF | CRLF | Native deriving (Show, Generic)
100
96
@@ -124,7 +120,7 @@ parseOptions options' defaults = do
124convertWithOpts :: Opt -> IO ()
120convertWithOpts :: Opt -> IO ()
125convertWithOpts opts = do
121convertWithOpts opts = do
126 let args = optInputFiles opts
122 let args = optInputFiles opts
127− let outputFile = optOutputFile opts
123+ let outputFile = fromMaybe "-" (optOutputFile opts)
128 let filters = optFilters opts
124 let filters = optFilters opts
129 let verbosity = optVerbosity opts
125 let verbosity = optVerbosity opts
130
126
@@ -245,18 +241,14 @@ convertWithOpts opts = do
245 (\(syn,dep) -> (T.unpack syn ++ " requires " ++
241 (\(syn,dep) -> (T.unpack syn ++ " requires " ++
246 T.unpack dep ++ " through IncludeRules.")) xs)
242 T.unpack dep ++ " through IncludeRules.")) xs)
247
243
248−
244+ -- We don't want to send output to the terminal if the user
249−
245+ -- does 'pandoc -t docx input.txt'; though we allow them to
250−#ifdef _WINDOWS
246+ -- force this with '-o -'.
251− let istty = True
252−#else
253− istty <- queryTerminal stdOutput
254−#endif
255− when (istty && not (isTextFormat format) && outputFile == "-") $
247+ when (not (isTextFormat format) && optOutputFile opts == Nothing) $
256 E.throwIO $ PandocAppError $
248 E.throwIO $ PandocAppError $
257 "Cannot write " ++ format ++ " output to stdout.\n" ++
249 "Cannot write " ++ format ++ " output to stdout.\n" ++
258− "Specify an output file using the -o option."
250+ "Specify an output file using the -o option, or " ++
259−
251+ "use '-o -' to force output to stdout."
260
252
261 let convertTabs = tabFilter (if optPreserveTabs opts || readerName == "t2t"
253 let convertTabs = tabFilter (if optPreserveTabs opts || readerName == "t2t"
262 then 0
254 then 0
@@ -303,7 +295,8 @@ convertWithOpts opts = do
303 variables <-
295 variables <-
304 withList (addStringAsVariable "sourcefile")
296 withList (addStringAsVariable "sourcefile")
305 (reverse $ optInputFiles opts)
297 (reverse $ optInputFiles opts)
306− (("outputfile", optOutputFile opts) : optVariables opts)
298+ (("outputfile", fromMaybe "-" (optOutputFile opts))
299+ : optVariables opts)
307 -- we reverse this list because, unlike
300 -- we reverse this list because, unlike
308 -- the other option lists here, it is
301 -- the other option lists here, it is
309 -- not reversed when parsed from CLI arguments.
302 -- not reversed when parsed from CLI arguments.
@@ -562,7 +555,7 @@ data Opt = Opt
562 , optTemplate :: Maybe FilePath -- ^ Custom template
555 , optTemplate :: Maybe FilePath -- ^ Custom template
563 , optVariables :: [(String,String)] -- ^ Template variables to set
556 , optVariables :: [(String,String)] -- ^ Template variables to set
564 , optMetadata :: [(String, String)] -- ^ Metadata fields to set
557 , optMetadata :: [(String, String)] -- ^ Metadata fields to set
565− , optOutputFile :: FilePath -- ^ Name of output file
558+ , optOutputFile :: Maybe FilePath -- ^ Name of output file
566 , optInputFiles :: [FilePath] -- ^ Names of input files
559 , optInputFiles :: [FilePath] -- ^ Names of input files
567 , optNumberSections :: Bool -- ^ Number sections in LaTeX
560 , optNumberSections :: Bool -- ^ Number sections in LaTeX
568 , optNumberOffset :: [Int] -- ^ Starting number for sections
561 , optNumberOffset :: [Int] -- ^ Starting number for sections
@@ -638,7 +631,7 @@ defaultOpts = Opt
638 , optTemplate = Nothing
631 , optTemplate = Nothing
639 , optVariables = []
632 , optVariables = []
640 , optMetadata = []
633 , optMetadata = []
641− , optOutputFile = "-" -- "-" means stdout
634+ , optOutputFile = Nothing
642 , optInputFiles = []
635 , optInputFiles = []
643 , optNumberSections = False
636 , optNumberSections = False
644 , optNumberOffset = [0,0,0,0,0,0]
637 , optNumberOffset = [0,0,0,0,0,0]
@@ -889,7 +882,7 @@ options =
889
882
890 , Option "o" ["output"]
883 , Option "o" ["output"]
891 (ReqArg
884 (ReqArg
892− (\arg opt -> return opt { optOutputFile = arg })
885+ (\arg opt -> return opt { optOutputFile = Just arg })
893 "FILE")
886 "FILE")
894 "" -- "Name of output file"
887 "" -- "Name of output file"
895
888