@@ -65,7 +65,7 @@ import System.Directory (Permissions (..), doesFileExist, findExecutable,
65import System.Environment (getArgs, getEnvironment, getProgName)
65import System.Environment (getArgs, getEnvironment, getProgName)
66import System.Exit (ExitCode (..), exitSuccess)
66import System.Exit (ExitCode (..), exitSuccess)
67import System.FilePath
67import System.FilePath
68−import System.IO (stdout)
68+import System.IO (stdout, nativeNewline, Newline(..))
69import System.IO.Error (isDoesNotExistError)
69import System.IO.Error (isDoesNotExistError)
70import Text.Pandoc
70import Text.Pandoc
71import Text.Pandoc.Builder (setMeta)
71import Text.Pandoc.Builder (setMeta)
@@ -411,6 +411,8 @@ convertWithOpts opts = do
411 return $ ("csl", jatsEncoded) : optMetadata opts
411 return $ ("csl", jatsEncoded) : optMetadata opts
412 else return $ optMetadata opts
412 else return $ optMetadata opts
414+ let eol = fromMaybe nativeNewline $ optEol opts
414 runIO' $ do
416 runIO' $ do
415 (doc, media) <- withMediaBag $ sourceToDoc sources >>=
417 (doc, media) <- withMediaBag $ sourceToDoc sources >>=
416 ( (if isJust (optExtractMedia opts)
418 ( (if isJust (optExtractMedia opts)
@@ -463,7 +465,7 @@ convertWithOpts opts = do
464 output <- f writerOptions doc
466 output <- f writerOptions doc
465 selfcontain (output ++ ['\n' | not standalone]) >>=
467 selfcontain (output ++ ['\n' | not standalone]) >>=
466− writerFn outputFile . handleEntities
468+ writerFn eol outputFile . handleEntities
468type Transform = Pandoc -> Pandoc
470type Transform = Pandoc -> Pandoc
@@ -567,6 +569,7 @@ data Opt = Opt
567 , optIncludeBeforeBody :: [FilePath] -- ^ Files to include before
569 , optIncludeBeforeBody :: [FilePath] -- ^ Files to include before
568 , optIncludeAfterBody :: [FilePath] -- ^ Files to include after body
570 , optIncludeAfterBody :: [FilePath] -- ^ Files to include after body
569 , optIncludeInHeader :: [FilePath] -- ^ Files to include in header
571 , optIncludeInHeader :: [FilePath] -- ^ Files to include in header
572+ , optEol :: Maybe Newline -- ^ Enforce line-endings
572-- | Defaults for command-line options.
575-- | Defaults for command-line options.
@@ -635,6 +638,7 @@ defaultOpts = Opt
635 , optIncludeBeforeBody = []
638 , optIncludeBeforeBody = []
636 , optIncludeAfterBody = []
639 , optIncludeAfterBody = []
637 , optIncludeInHeader = []
640 , optIncludeInHeader = []
640addMetadata :: (String, String) -> Pandoc -> Pandoc
644addMetadata :: (String, String) -> Pandoc -> Pandoc
@@ -783,9 +787,9 @@ writeFnBinary :: MonadIO m => FilePath -> B.ByteString -> m ()
783writeFnBinary "-" = liftIO . B.putStr
787writeFnBinary "-" = liftIO . B.putStr
784writeFnBinary f = liftIO . B.writeFile (UTF8.encodePath f)
788writeFnBinary f = liftIO . B.writeFile (UTF8.encodePath f)
786−writerFn :: MonadIO m => FilePath -> String -> m ()
790+writerFn :: MonadIO m => Newline -> FilePath -> String -> m ()
787−writerFn "-" = liftIO . UTF8.putStr
791+writerFn eol "-" = liftIO . UTF8.putStrWith eol
788−writerFn f = liftIO . UTF8.writeFile f
792+writerFn eol f = liftIO . UTF8.writeFileWith eol f
790lookupHighlightStyle :: Maybe String -> IO (Maybe Style)
794lookupHighlightStyle :: Maybe String -> IO (Maybe Style)
791lookupHighlightStyle Nothing = return Nothing
795lookupHighlightStyle Nothing = return Nothing
@@ -958,6 +962,18 @@ options =
958 "NUMBER")
962 "NUMBER")
959 "" -- "Dpi (default 96)"
963 "" -- "Dpi (default 96)"
968+ case toLower <$> arg of
969+ "crlf" -> return opt { optEol = Just CRLF }
970+ "lf" -> return opt { optEol = Just LF }
971+ -- mac-syntax (cr) is not supported in ghc-base.
972+ _ -> E.throwIO $ PandocOptionError
973+ "--eol must be one of crlf (Windows), lf (Unix)")
975+ "" -- "EOL (default OS-dependent)"
961 , Option "" ["wrap"]
977 , Option "" ["wrap"]
963 (\arg opt ->
979 (\arg opt ->