From 1ecc48e9f9b027e9b1226fa3a43b52ae8c7004bf Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 7 Feb 2017 21:42:35 +0100 Subject: Moved readFileFromDirs to Text.Pandoc.Class. This can be used in several different modules, not just LaTeX reader. --- src/Text/Pandoc/Class.hs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/Text/Pandoc/Class.hs') 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} -- cgit v1.2.3