{-# LANGUAGE OverloadedStrings #-}
module Text.Pandoc.App.FormatHeuristics
( formatFromFilePaths
) where
import Data.Char (toLower)
import Data.Text (Text)
import System.FilePath (takeExtension)
formatFromFilePaths :: [FilePath] -> Maybe Text
formatFromFilePaths [] = Nothing
formatFromFilePaths (x:xs) =
case formatFromFilePath x of
Just f -> Just f
Nothing -> formatFromFilePaths xs
formatFromFilePath :: FilePath -> Maybe Text
formatFromFilePath x =
case takeExtension (map toLower x) of
".adoc" -> Just "asciidoc"
".asciidoc" -> Just "asciidoc"
".context" -> Just "context"
".ctx" -> Just "context"
".db" -> Just "docbook"
".doc" -> Just "doc"
".docx" -> Just "docx"
".dokuwiki" -> Just "dokuwiki"
".epub" -> Just "epub"
".fb2" -> Just "fb2"
".htm" -> Just "html"
".html" -> Just "html"
".icml" -> Just "icml"
".json" -> Just "json"
".latex" -> Just "latex"
".lhs" -> Just "markdown+lhs"
".ltx" -> Just "latex"
".markdown" -> Just "markdown"
".md" -> Just "markdown"
".ms" -> Just "ms"
".muse" -> Just "muse"
".native" -> Just "native"
".odt" -> Just "odt"
".opml" -> Just "opml"
".org" -> Just "org"
".pdf" -> Just "pdf"
".pptx" -> Just "pptx"
".roff" -> Just "ms"
".rst" -> Just "rst"
".rtf" -> Just "rtf"
".s5" -> Just "s5"
".t2t" -> Just "t2t"
".tei" -> Just "tei"
".tei.xml" -> Just "tei"
".tex" -> Just "latex"
".texi" -> Just "texinfo"
".texinfo" -> Just "texinfo"
".text" -> Just "markdown"
".textile" -> Just "textile"
".txt" -> Just "markdown"
".wiki" -> Just "mediawiki"
".xhtml" -> Just "html"
".ipynb" -> Just "ipynb"
".csv" -> Just "csv"
['.',y] | y `elem` ['1'..'9'] -> Just "man"
_ -> Nothing