diff options
author | John MacFarlane <jgm@berkeley.edu> | 2013-07-18 20:58:14 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2013-07-18 20:58:14 -0700 |
commit | 7c980f39bf1cff941d3e78056fd69e0b371833e3 (patch) | |
tree | becd213055d516dcc1a6cfa4d472a23503a6b0c8 /src/Text/Pandoc/Writers/EPUB.hs | |
parent | 6c2e76ac617e5972db5d118525e7f6f59f43caac (diff) |
Improved fetching of external resources.
* In Shared, openURL and fetchItem now return an Either, for
better error handling. (API change.)
* Better error message when fetching a URL fails with
`--self-contained`.
* EPUB writer: If resource not found, skip it, as in Docx writer.
* Closes #916.
Diffstat (limited to 'src/Text/Pandoc/Writers/EPUB.hs')
-rw-r--r-- | src/Text/Pandoc/Writers/EPUB.hs | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/Text/Pandoc/Writers/EPUB.hs b/src/Text/Pandoc/Writers/EPUB.hs index f171a2560..42863ef86 100644 --- a/src/Text/Pandoc/Writers/EPUB.hs +++ b/src/Text/Pandoc/Writers/EPUB.hs @@ -123,10 +123,15 @@ writeEPUB opts doc@(Pandoc meta _) = do Pandoc _ blocks <- bottomUpM (transformInline opts' sourceDir picsRef) doc pics <- readIORef picsRef - let readPicEntry (oldsrc, newsrc) = do - (img,_) <- fetchItem sourceDir oldsrc - return $ toEntry newsrc epochtime $ B.fromChunks . (:[]) $ img - picEntries <- mapM readPicEntry pics + let readPicEntry entries (oldsrc, newsrc) = do + res <- fetchItem sourceDir oldsrc + case res of + Left e -> do + warn $ "Could not find image `" ++ oldsrc ++ "', skipping..." + return entries + Right (img,_) -> return $ + (toEntry newsrc epochtime $ B.fromChunks . (:[]) $ img) : entries + picEntries <- foldM readPicEntry [] pics -- handle fonts let mkFontEntry f = mkEntry (takeFileName f) `fmap` B.readFile f |