summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Class.hs
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-02-07 21:42:35 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2017-02-07 21:42:35 +0100
commit1ecc48e9f9b027e9b1226fa3a43b52ae8c7004bf (patch)
treeae9e58d00503c319b1048e9ff24b55aa671f5bc1 /src/Text/Pandoc/Class.hs
parent9db98550dfc39d31072e43ac066154a483865fc4 (diff)
Moved readFileFromDirs to Text.Pandoc.Class.
This can be used in several different modules, not just LaTeX reader.
Diffstat (limited to 'src/Text/Pandoc/Class.hs')
-rw-r--r--src/Text/Pandoc/Class.hs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/Text/Pandoc/Class.hs b/src/Text/Pandoc/Class.hs
index 348da71ba..f75db4b3a 100644
--- a/src/Text/Pandoc/Class.hs
+++ b/src/Text/Pandoc/Class.hs
@@ -44,6 +44,7 @@ module Text.Pandoc.Class ( PandocMonad(..)
, warningWithPos
, report
, getLog
+ , readFileFromDirs
, setVerbosity
, getMediaBag
, setMediaBag
@@ -206,6 +207,15 @@ getZonedTime = do
tz <- getCurrentTimeZone
return $ utcToZonedTime tz t
+-- | Read file, checking in any number of directories.
+readFileFromDirs :: PandocMonad m => [FilePath] -> FilePath -> m String
+readFileFromDirs [] f = do
+ warning $ "Could not load include file " ++ f ++ ", skipping."
+ return ""
+readFileFromDirs (d:ds) f = catchError
+ (UTF8.toStringLazy <$> readFileLazy (d </> f))
+ (\_ -> readFileFromDirs ds f)
+
--
newtype DeferredMediaPath = DeferredMediaPath {unDefer :: String}