diff options
Diffstat (limited to 'src/Text/Pandoc/Shared.hs')
-rw-r--r-- | src/Text/Pandoc/Shared.hs | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs index 362db2fed..2090e1734 100644 --- a/src/Text/Pandoc/Shared.hs +++ b/src/Text/Pandoc/Shared.hs @@ -132,7 +132,7 @@ import qualified Data.Text as T (toUpper, pack, unpack) import Data.ByteString.Lazy (toChunks) #ifdef EMBED_DATA_FILES -import Text.Pandoc.Data (dataFiles) +import Text.Pandoc.Data (dataFiles, readmeFile) #else import Paths_pandoc (getDataFileName) #endif @@ -743,6 +743,12 @@ inDirectory path action = E.bracket (const $ setCurrentDirectory path >> action) readDefaultDataFile :: FilePath -> IO BS.ByteString +readDefaultDataFile "README" = +#ifdef EMBED_DATA_FILES + return readmeFile +#else + getDataFileName "README" >>= checkExistence >>= BS.readFile +#endif readDefaultDataFile fname = #ifdef EMBED_DATA_FILES case lookup (makeCanonical fname) dataFiles of @@ -755,13 +761,15 @@ readDefaultDataFile fname = go as x = x : as #else getDataFileName ("data" </> fname) >>= checkExistence >>= BS.readFile - where checkExistence fn = do - exists <- doesFileExist fn - if exists - then return fn - else err 97 ("Could not find data file " ++ fname) #endif +checkExistence :: FilePath -> IO FilePath +checkExistence fn = do + exists <- doesFileExist fn + if exists + then return fn + else err 97 ("Could not find data file " ++ fn) + -- | Read file from specified user data directory or, if not found there, from -- Cabal data directory. readDataFile :: Maybe FilePath -> FilePath -> IO BS.ByteString |