git.iko.soy/typeable/pandoc
on master help sign in
Change formatForFilePaths to return a Maybe.
ed0548dJohn MacFarlane
src/Text/Pandoc/App.hs+2−1
@@ -104,7 +104,8 @@ convertWithOpts opts = do
104 -- assign reader and writer based on options and filenames
104 -- assign reader and writer based on options and filenames
105 let readerName = case optReader opts of
105 let readerName = case optReader opts of
106 Just f -> f
106 Just f -> f
107+ Nothing -> fromMaybe fallback $
107− Nothing -> formatFromFilePaths fallback sources
108+ formatFromFilePaths sources
108 where fallback = if any isURI sources
109 where fallback = if any isURI sources
109 then "html"
110 then "html"
110 else "markdown"
111 else "markdown"
src/Text/Pandoc/App/FormatHeuristics.hs+6−6
@@ -18,13 +18,13 @@ import Prelude
18import Data.Char (toLower)
18import Data.Char (toLower)
19import System.FilePath (takeExtension)
19import System.FilePath (takeExtension)
20
20
21−-- Determine default reader based on source file extensions.
21+-- Determine default format based on file extensions.
22−formatFromFilePaths :: String -> [FilePath] -> String
22+formatFromFilePaths :: [FilePath] -> Maybe String
23−formatFromFilePaths fallback [] = fallback
23+formatFromFilePaths [] = Nothing
24−formatFromFilePaths fallback (x:xs) =
24+formatFromFilePaths (x:xs) =
25 case formatFromFilePath x of
25 case formatFromFilePath x of
26− Just f -> f
26+ Just f -> Just f
27− Nothing -> formatFromFilePaths fallback xs
27+ Nothing -> formatFromFilePaths xs
28
28
29-- Determine format based on file extension
29-- Determine format based on file extension
30formatFromFilePath :: FilePath -> Maybe String
30formatFromFilePath :: FilePath -> Maybe String
src/Text/Pandoc/App/OutputSettings.hs+2−1
@@ -71,7 +71,8 @@ optToOutputSettings opts = do
71 then liftIO $ pdfWriterAndProg (optWriter opts) (optPdfEngine opts)
71 then liftIO $ pdfWriterAndProg (optWriter opts) (optPdfEngine opts)
72 else case optWriter opts of
72 else case optWriter opts of
73 Nothing ->
73 Nothing ->
74− return (formatFromFilePaths "html" [outputFile], Nothing)
74+ return (fromMaybe "html" $ formatFromFilePaths [outputFile],
75+ Nothing)
75 Just f -> return (f, Nothing)
76 Just f -> return (f, Nothing)
76
77
77 let format = if ".lua" `isSuffixOf` writerName
78 let format = if ".lua" `isSuffixOf` writerName