aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2011-11-20 12:32:54 -0800
committerJohn MacFarlane <fiddlosopher@gmail.com>2011-11-20 12:32:54 -0800
commit9383260e20b4f899fce9982aa2255d40ab9d48f6 (patch)
tree6e08ac21d9aaf27b10aada9a1b3c4e5e0e4bf291 /src
parentef9395ced7db625e4cb2181ee70ab416e1f8b9e8 (diff)
downloadpandoc-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.hs14
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)