git.iko.soy/typeable/pandoc
on master help sign in
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

commitd704f47b86f49a46fab91969ae3fc92957cc8149 authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateThu 18 Mar 2010, 06:45 (17 years ago) parent6959611
1 file changed+9−6
src/pandoc.hs+9−6
src/pandoc.hs+9−6
@@ -60,7 +60,7 @@ import Text.Pandoc.Biblio
6060#endif
6161import Control.Monad (when, unless, liftM)
6262import Network.HTTP (simpleHTTP, mkRequest, getResponseBody, RequestMethod(..))
63−import Network.URI (parseURI)
63+import Network.URI (parseURI, isURI)
6464import Data.ByteString.Lazy.UTF8 (toString)
6565
6666copyrightMessage :: String
@@ -536,9 +536,9 @@ usageMessage programName = usageInfo
536536 (intercalate ", " $ map fst writers) ++ "\nOptions:")
537537
538538-- Determine default reader based on source file extensions
539−defaultReaderName :: [FilePath] -> String
540−defaultReaderName [] = "markdown"
541−defaultReaderName (x:xs) =
539+defaultReaderName :: String -> [FilePath] -> String
540+defaultReaderName fallback [] = fallback
541+defaultReaderName fallback (x:xs) =
542542 case takeExtension (map toLower x) of
543543 ".xhtml" -> "html"
544544 ".html" -> "html"
@@ -549,7 +549,7 @@ defaultReaderName (x:xs) =
549549 ".rst" -> "rst"
550550 ".lhs" -> "markdown+lhs"
551551 ".native" -> "native"
552− _ -> defaultReaderName xs
552+ _ -> defaultReaderName fallback xs
553553
554554-- Returns True if extension of first source is .lhs
555555lhsExtension :: [FilePath] -> Bool
@@ -667,7 +667,10 @@ main = do
667667
668668 -- assign reader and writer based on options and filenames
669669 let readerName' = if null readerName
670− then defaultReaderName sources
670+ then let fallback = if any isURI sources
671+ then "html"
672+ else "markdown"
673+ in defaultReaderName fallback sources
671674 else readerName
672675
673676 let writerName' = if null writerName