@@ -65,7 +65,7 @@ import System.Directory (Permissions (..), doesFileExist, findExecutable,
6565import System.Environment (getArgs, getEnvironment, getProgName)
6666import System.Exit (ExitCode (..), exitSuccess)
6767import System.FilePath
68−import System.IO (stdout)
68+import System.IO (stdout, nativeNewline, Newline(..))
6969import System.IO.Error (isDoesNotExistError)
7070import Text.Pandoc
7171import Text.Pandoc.Builder (setMeta)
@@ -411,6 +411,8 @@ convertWithOpts opts = do
411411 return $ ("csl", jatsEncoded) : optMetadata opts
412412 else return $ optMetadata opts
413413
414+ let eol = fromMaybe nativeNewline $ optEol opts
415+
414416 runIO' $ do
415417 (doc, media) <- withMediaBag $ sourceToDoc sources >>=
416418 ( (if isJust (optExtractMedia opts)
@@ -463,7 +465,7 @@ convertWithOpts opts = do
463465 else id
464466 output <- f writerOptions doc
465467 selfcontain (output ++ ['\n' | not standalone]) >>=
466− writerFn outputFile . handleEntities
468+ writerFn eol outputFile . handleEntities
467469
468470type Transform = Pandoc -> Pandoc
469471
@@ -567,6 +569,7 @@ data Opt = Opt
567569 , optIncludeBeforeBody :: [FilePath] -- ^ Files to include before
568570 , optIncludeAfterBody :: [FilePath] -- ^ Files to include after body
569571 , optIncludeInHeader :: [FilePath] -- ^ Files to include in header
572+ , optEol :: Maybe Newline -- ^ Enforce line-endings
570573 }
571574
572575-- | Defaults for command-line options.
@@ -635,6 +638,7 @@ defaultOpts = Opt
635638 , optIncludeBeforeBody = []
636639 , optIncludeAfterBody = []
637640 , optIncludeInHeader = []
641+ , optEol = Nothing
638642 }
639643
640644addMetadata :: (String, String) -> Pandoc -> Pandoc
@@ -783,9 +787,9 @@ writeFnBinary :: MonadIO m => FilePath -> B.ByteString -> m ()
783787writeFnBinary "-" = liftIO . B.putStr
784788writeFnBinary f = liftIO . B.writeFile (UTF8.encodePath f)
785789
786−writerFn :: MonadIO m => FilePath -> String -> m ()
787−writerFn "-" = liftIO . UTF8.putStr
788−writerFn f = liftIO . UTF8.writeFile f
790+writerFn :: MonadIO m => Newline -> FilePath -> String -> m ()
791+writerFn eol "-" = liftIO . UTF8.putStrWith eol
792+writerFn eol f = liftIO . UTF8.writeFileWith eol f
789793
790794lookupHighlightStyle :: Maybe String -> IO (Maybe Style)
791795lookupHighlightStyle Nothing = return Nothing
@@ -958,6 +962,18 @@ options =
958962 "NUMBER")
959963 "" -- "Dpi (default 96)"
960964
965+ , Option "" ["eol"]
966+ (ReqArg
967+ (\arg opt ->
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)")
974+ "crlf|lf")
975+ "" -- "EOL (default OS-dependent)"
976+
961977 , Option "" ["wrap"]
962978 (ReqArg
963979 (\arg opt ->