summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Shared.hs
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2013-08-11 15:58:09 -0700
committerJohn MacFarlane <fiddlosopher@gmail.com>2013-08-11 15:58:09 -0700
commite279175ea517e2df65fe5d716bc02e383b04fc36 (patch)
treecafdb6b78c8a399e8fb0ac9c8e1c3ba5a8fef153 /src/Text/Pandoc/Shared.hs
parent6f736dfa7578faab7b90546ee5b2c275185968c8 (diff)
Options: Changed `writerSourceDir` to `writerSourceURL` (now a Maybe).
Previously we used to store the directory of the first input file, even if it was local, and used this as a base directory for finding images in ODT, EPUB, Docx, and PDF. This has been confusing to many users. It seems better to look for images relative to the current working directory, even if the first file argument is in another directory. writerSourceURL is set to 'Just url' when the first command-line argument is an absolute URL. (So, relative links will be resolved in relation to the first page.) Otherwise, 'Nothing'. The ODT, EPUB, Docx, and PDF writers have been modified accordingly. Note that this change may break some existing workflows. If you have been assuming that relative links will be interpreted relative to the directory of the first file argument, you'll need to make that the current directory before running pandoc. Closes #942.
Diffstat (limited to 'src/Text/Pandoc/Shared.hs')
-rw-r--r--src/Text/Pandoc/Shared.hs20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs
index 6fd78b188..d670a35bc 100644
--- a/src/Text/Pandoc/Shared.hs
+++ b/src/Text/Pandoc/Shared.hs
@@ -612,18 +612,18 @@ readDataFileUTF8 userDir fname =
-- | Fetch an image or other item from the local filesystem or the net.
-- Returns raw content and maybe mime type.
-fetchItem :: String -> String
+fetchItem :: Maybe String -> String
-> IO (Either E.SomeException (BS.ByteString, Maybe String))
-fetchItem sourceDir s =
- case s of
- _ | isAbsoluteURI s -> openURL s
- | isAbsoluteURI sourceDir -> openURL $ sourceDir ++ "/" ++ s
- | otherwise -> E.try $ do
+fetchItem sourceURL s
+ | isAbsoluteURI s = openURL s
+ | otherwise = case sourceURL of
+ Just u -> openURL (u ++ "/" ++ s)
+ Nothing -> E.try readLocalFile
+ where readLocalFile = do
let mime = case takeExtension s of
- ".gz" -> getMimeType $ dropExtension s
- x -> getMimeType x
- let f = sourceDir </> s
- cont <- BS.readFile f
+ ".gz" -> getMimeType $ dropExtension s
+ x -> getMimeType x
+ cont <- BS.readFile s
return (cont, mime)
-- | Read from a URL and return raw data and maybe mime type.