aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2019-07-14 10:48:38 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2019-07-14 10:48:38 -0700
commited0548d8983d0e2a3bd50602d166837b13e31a85 (patch)
treef8ede30a77b9aa50bb17235537897f72c55dafa2 /src/Text
parent968d2046a3cb6db661673be580660ac402753c34 (diff)
downloadpandoc-ed0548d8983d0e2a3bd50602d166837b13e31a85.tar.gz
Change formatForFilePaths to return a Maybe.
Internal change. This will make it easier to emit messages when we're guessing at a format.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/App.hs3
-rw-r--r--src/Text/Pandoc/App/FormatHeuristics.hs12
-rw-r--r--src/Text/Pandoc/App/OutputSettings.hs3
3 files changed, 10 insertions, 8 deletions
diff --git a/src/Text/Pandoc/App.hs b/src/Text/Pandoc/App.hs
index aabefc64a..d48ae1932 100644
--- a/src/Text/Pandoc/App.hs
+++ b/src/Text/Pandoc/App.hs
@@ -104,7 +104,8 @@ convertWithOpts opts = do
-- assign reader and writer based on options and filenames
let readerName = case optReader opts of
Just f -> f
- Nothing -> formatFromFilePaths fallback sources
+ Nothing -> fromMaybe fallback $
+ formatFromFilePaths sources
where fallback = if any isURI sources
then "html"
else "markdown"
diff --git a/src/Text/Pandoc/App/FormatHeuristics.hs b/src/Text/Pandoc/App/FormatHeuristics.hs
index 6198e83dc..a02d8d15e 100644
--- a/src/Text/Pandoc/App/FormatHeuristics.hs
+++ b/src/Text/Pandoc/App/FormatHeuristics.hs
@@ -18,13 +18,13 @@ import Prelude
import Data.Char (toLower)
import System.FilePath (takeExtension)
--- Determine default reader based on source file extensions.
-formatFromFilePaths :: String -> [FilePath] -> String
-formatFromFilePaths fallback [] = fallback
-formatFromFilePaths fallback (x:xs) =
+-- Determine default format based on file extensions.
+formatFromFilePaths :: [FilePath] -> Maybe String
+formatFromFilePaths [] = Nothing
+formatFromFilePaths (x:xs) =
case formatFromFilePath x of
- Just f -> f
- Nothing -> formatFromFilePaths fallback xs
+ Just f -> Just f
+ Nothing -> formatFromFilePaths xs
-- Determine format based on file extension
formatFromFilePath :: FilePath -> Maybe String
diff --git a/src/Text/Pandoc/App/OutputSettings.hs b/src/Text/Pandoc/App/OutputSettings.hs
index 837636503..a9034d6f2 100644
--- a/src/Text/Pandoc/App/OutputSettings.hs
+++ b/src/Text/Pandoc/App/OutputSettings.hs
@@ -71,7 +71,8 @@ optToOutputSettings opts = do
then liftIO $ pdfWriterAndProg (optWriter opts) (optPdfEngine opts)
else case optWriter opts of
Nothing ->
- return (formatFromFilePaths "html" [outputFile], Nothing)
+ return (fromMaybe "html" $ formatFromFilePaths [outputFile],
+ Nothing)
Just f -> return (f, Nothing)
let format = if ".lua" `isSuffixOf` writerName