aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbert Krewinkel <albert@zeitkraut.de>2021-03-13 22:03:36 +0100
committerAlbert Krewinkel <albert@zeitkraut.de>2021-03-13 22:06:43 +0100
commit35688c42627dce4641f4f61253e3d3786452b61a (patch)
treeb57967ef038d18c4e954189e14686d074f2f23c9
parent35b66a76718205c303f416bf0afc01c098e8a171 (diff)
downloadpandoc-35688c42627dce4641f4f61253e3d3786452b61a.tar.gz
T.P.App.FormatHeuristics: shorten code, improve docs.
-rw-r--r--src/Text/Pandoc/App/FormatHeuristics.hs20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/Text/Pandoc/App/FormatHeuristics.hs b/src/Text/Pandoc/App/FormatHeuristics.hs
index 65a1a7b82..bdf8c6667 100644
--- a/src/Text/Pandoc/App/FormatHeuristics.hs
+++ b/src/Text/Pandoc/App/FormatHeuristics.hs
@@ -15,18 +15,24 @@ module Text.Pandoc.App.FormatHeuristics
) where
import Data.Char (toLower)
+import Data.Foldable (asum)
import Data.Text (Text)
import System.FilePath (takeExtension)
--- Determine default format based on file extensions.
+-- | Determines default format based on file extensions; uses the format
+-- of the first extension that's associated with a format.
+--
+-- Examples:
+--
+-- > formatFromFilePaths ["text.unknown", "no-extension"]
+-- Nothing
+--
+-- > formatFromFilePaths ["my.md", "other.rst"]
+-- Just "markdown"
formatFromFilePaths :: [FilePath] -> Maybe Text
-formatFromFilePaths [] = Nothing
-formatFromFilePaths (x:xs) =
- case formatFromFilePath x of
- Just f -> Just f
- Nothing -> formatFromFilePaths xs
+formatFromFilePaths = asum . map formatFromFilePath
--- Determine format based on file extension
+-- | Determines format based on file extension.
formatFromFilePath :: FilePath -> Maybe Text
formatFromFilePath x =
case takeExtension (map toLower x) of