@@ -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
95−import System.Posix.IO (stdOutput)
96−import System.Posix.Terminal (queryTerminal)
99data LineEnding = LF | CRLF | Native deriving (Show, Generic)
95data LineEnding = LF | CRLF | Native deriving (Show, Generic)
@@ -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
@@ -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)
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 -'.
253− istty <- queryTerminal stdOutput
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."
261 let convertTabs = tabFilter (if optPreserveTabs opts || readerName == "t2t"
253 let convertTabs = tabFilter (if optPreserveTabs opts || readerName == "t2t"
@@ -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 =
890 , Option "o" ["output"]
883 , Option "o" ["output"]
892− (\arg opt -> return opt { optOutputFile = arg })
885+ (\arg opt -> return opt { optOutputFile = Just arg })
894 "" -- "Name of output file"
887 "" -- "Name of output file"