git.iko.soy/typeable/pandoc
on master help sign in
T.P.App.FormatHeuristics: shorten code, improve docs.
commit35688c42627dce4641f4f61253e3d3786452b61a authorAlbert Krewinkel <albert@zeitkraut.de> dateSat 13 Mar 2021, 22:03 (6 years ago) parent35b66a7
1 file changed+13−7
src/Text/Pandoc/App/FormatHeuristics.hs+13−7
src/Text/Pandoc/App/FormatHeuristics.hs+13−7
@@ -15,18 +15,24 @@ module Text.Pandoc.App.FormatHeuristics
1515 ) where
1616
1717import Data.Char (toLower)
18+import Data.Foldable (asum)
1819import Data.Text (Text)
1920import System.FilePath (takeExtension)
2021
21−-- Determine default format based on file extensions.
22+-- | Determines default format based on file extensions; uses the format
23+-- of the first extension that's associated with a format.
24+--
25+-- Examples:
26+--
27+-- > formatFromFilePaths ["text.unknown", "no-extension"]
28+-- Nothing
29+--
30+-- > formatFromFilePaths ["my.md", "other.rst"]
31+-- Just "markdown"
2232formatFromFilePaths :: [FilePath] -> Maybe Text
23−formatFromFilePaths [] = Nothing
24−formatFromFilePaths (x:xs) =
25− case formatFromFilePath x of
26− Just f -> Just f
27− Nothing -> formatFromFilePaths xs
33+formatFromFilePaths = asum . map formatFromFilePath
2834
29−-- Determine format based on file extension
35+-- | Determines format based on file extension.
3036formatFromFilePath :: FilePath -> Maybe Text
3137formatFromFilePath x =
3238 case takeExtension (map toLower x) of