diff options
author | John MacFarlane <fiddlosopher@gmail.com> | 2011-11-20 12:32:54 -0800 |
---|---|---|
committer | John MacFarlane <fiddlosopher@gmail.com> | 2011-11-20 12:32:54 -0800 |
commit | 9383260e20b4f899fce9982aa2255d40ab9d48f6 (patch) | |
tree | 6e08ac21d9aaf27b10aada9a1b3c4e5e0e4bf291 /src | |
parent | ef9395ced7db625e4cb2181ee70ab416e1f8b9e8 (diff) | |
download | pandoc-9383260e20b4f899fce9982aa2255d40ab9d48f6.tar.gz |
Offline: Look for relative URLs in data directory if not found.
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/Offline.hs | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Offline.hs b/src/Text/Pandoc/Offline.hs index c0d6edef9..4ae365156 100644 --- a/src/Text/Pandoc/Offline.hs +++ b/src/Text/Pandoc/Offline.hs @@ -42,12 +42,24 @@ import System.FilePath (takeExtension, dropExtension, takeDirectory, (</>)) import Data.Char (toLower, isAscii, isAlphaNum) import Codec.Compression.GZip as Gzip import qualified Data.ByteString.Lazy as L +import Text.Pandoc.Shared (findDataFile) +import System.Directory (doesFileExist) getItem :: String -> IO ByteString getItem f = if isAbsoluteURI f then openURL f - else B.readFile f + else do + let userDataDir = "." -- TODO writeUserDataDir + exists <- doesFileExist f + if exists + then B.readFile f + else do + res <- findDataFile (Just userDataDir) f + exists' <- doesFileExist res + if exists' + then B.readFile res + else B.readFile f -- will throw error openURL :: String -> IO ByteString openURL u = getResponseBody =<< simpleHTTP (getReq u) |