git.iko.soy/typeable/pandoc
on master help sign in
Change formatForFilePaths to return a Maybe.

Internal change. This will make it easier to emit messages when we're guessing at a format.

commited0548d8983d0e2a3bd50602d166837b13e31a85 authorJohn MacFarlane <jgm@berkeley.edu> dateSun 14 Jul 2019, 10:48 (7 years ago) parent968d204
3 files changed+10−8
src/Text/Pandoc/App.hs+2−1 src/Text/Pandoc/App/FormatHeuristics.hs+6−6 src/Text/Pandoc/App/OutputSettings.hs+2−1
src/Text/Pandoc/App.hs+2−1
@@ -104,7 +104,8 @@ convertWithOpts opts = do
104104 -- assign reader and writer based on options and filenames
105105 let readerName = case optReader opts of
106106 Just f -> f
107− Nothing -> formatFromFilePaths fallback sources
107+ Nothing -> fromMaybe fallback $
108+ formatFromFilePaths sources
108109 where fallback = if any isURI sources
109110 then "html"
110111 else "markdown"
src/Text/Pandoc/App/FormatHeuristics.hs+6−6
@@ -18,13 +18,13 @@ import Prelude
1818import Data.Char (toLower)
1919import System.FilePath (takeExtension)
2020
21−-- Determine default reader based on source file extensions.
22−formatFromFilePaths :: String -> [FilePath] -> String
23−formatFromFilePaths fallback [] = fallback
24−formatFromFilePaths fallback (x:xs) =
21+-- Determine default format based on file extensions.
22+formatFromFilePaths :: [FilePath] -> Maybe String
23+formatFromFilePaths [] = Nothing
24+formatFromFilePaths (x:xs) =
2525 case formatFromFilePath x of
26− Just f -> f
27− Nothing -> formatFromFilePaths fallback xs
26+ Just f -> Just f
27+ Nothing -> formatFromFilePaths xs
2828
2929-- Determine format based on file extension
3030formatFromFilePath :: FilePath -> Maybe String
src/Text/Pandoc/App/OutputSettings.hs+2−1
@@ -71,7 +71,8 @@ optToOutputSettings opts = do
7171 then liftIO $ pdfWriterAndProg (optWriter opts) (optPdfEngine opts)
7272 else case optWriter opts of
7373 Nothing ->
74− return (formatFromFilePaths "html" [outputFile], Nothing)
74+ return (fromMaybe "html" $ formatFromFilePaths [outputFile],
75+ Nothing)
7576 Just f -> return (f, Nothing)
7677
7778 let format = if ".lua" `isSuffixOf` writerName