diff options
author | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2010-03-18 06:45:50 +0000 |
---|---|---|
committer | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2010-03-18 06:45:50 +0000 |
commit | d704f47b86f49a46fab91969ae3fc92957cc8149 (patch) | |
tree | 802fbfedd7e879ff3d096394c9d58d77be192fd3 /src | |
parent | 695961155a00738160b05c25588b6b02f681a18e (diff) | |
download | pandoc-d704f47b86f49a46fab91969ae3fc92957cc8149.tar.gz |
Better heuristics for guessing reader to use.
If argument is an absolute URL without a recognized extension,
and no reader is explicitly specified, use HTML.
git-svn-id: https://pandoc.googlecode.com/svn/trunk@1908 788f1e2b-df1e-0410-8736-df70ead52e1b
Diffstat (limited to 'src')
-rw-r--r-- | src/pandoc.hs | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/pandoc.hs b/src/pandoc.hs index 48a832e2d..cd2768bfc 100644 --- a/src/pandoc.hs +++ b/src/pandoc.hs @@ -60,7 +60,7 @@ import Text.Pandoc.Biblio #endif import Control.Monad (when, unless, liftM) import Network.HTTP (simpleHTTP, mkRequest, getResponseBody, RequestMethod(..)) -import Network.URI (parseURI) +import Network.URI (parseURI, isURI) import Data.ByteString.Lazy.UTF8 (toString) copyrightMessage :: String @@ -536,9 +536,9 @@ usageMessage programName = usageInfo (intercalate ", " $ map fst writers) ++ "\nOptions:") -- Determine default reader based on source file extensions -defaultReaderName :: [FilePath] -> String -defaultReaderName [] = "markdown" -defaultReaderName (x:xs) = +defaultReaderName :: String -> [FilePath] -> String +defaultReaderName fallback [] = fallback +defaultReaderName fallback (x:xs) = case takeExtension (map toLower x) of ".xhtml" -> "html" ".html" -> "html" @@ -549,7 +549,7 @@ defaultReaderName (x:xs) = ".rst" -> "rst" ".lhs" -> "markdown+lhs" ".native" -> "native" - _ -> defaultReaderName xs + _ -> defaultReaderName fallback xs -- Returns True if extension of first source is .lhs lhsExtension :: [FilePath] -> Bool @@ -667,7 +667,10 @@ main = do -- assign reader and writer based on options and filenames let readerName' = if null readerName - then defaultReaderName sources + then let fallback = if any isURI sources + then "html" + else "markdown" + in defaultReaderName fallback sources else readerName let writerName' = if null writerName |