git.iko.soy/typeable/pandoc
on master help sign in
EPUB Reader: Changed image paths to be relative to manifest file
a6648e5Matthew Pickering
src/Text/Pandoc/Readers/EPUB.hs+6−6
@@ -55,7 +55,7 @@ archiveToEPUB os archive = do
55 meta <- parseMeta content
55 meta <- parseMeta content
56 (cover, items) <- parseManifest content
56 (cover, items) <- parseManifest content
57 -- No need to collapse here as the image path is from the manifest file
57 -- No need to collapse here as the image path is from the manifest file
58− let coverDoc = fromMaybe mempty (imageToPandoc . (root </>) <$> cover)
58+ let coverDoc = fromMaybe mempty (imageToPandoc <$> cover)
59 spine <- parseSpine items content
59 spine <- parseSpine items content
60 let escapedSpine = map (escapeURI . takeFileName . fst) spine
60 let escapedSpine = map (escapeURI . takeFileName . fst) spine
61 Pandoc _ bs <-
61 Pandoc _ bs <-
@@ -69,17 +69,17 @@ archiveToEPUB os archive = do
69 parseSpineElem :: MonadError String m => FilePath -> (FilePath, MIME) -> m Pandoc
69 parseSpineElem :: MonadError String m => FilePath -> (FilePath, MIME) -> m Pandoc
70 parseSpineElem (normalise -> r) (normalise -> path, mime) = do
70 parseSpineElem (normalise -> r) (normalise -> path, mime) = do
71 when (readerTrace os) (traceM path)
71 when (readerTrace os) (traceM path)
72− doc <- mimeToReader mime (r </> path)
72+ doc <- mimeToReader mime r path
73 let docSpan = B.doc $ B.para $ B.spanWith (takeFileName path, [], []) mempty
73 let docSpan = B.doc $ B.para $ B.spanWith (takeFileName path, [], []) mempty
74 return $ docSpan <> doc
74 return $ docSpan <> doc
75− mimeToReader :: MonadError String m => MIME -> FilePath -> m Pandoc
75+ mimeToReader :: MonadError String m => MIME -> FilePath -> FilePath -> m Pandoc
76− mimeToReader "application/xhtml+xml" (normalise -> path) = do
76+ mimeToReader "application/xhtml+xml" (normalise -> root) (normalise -> path) = do
77− fname <- findEntryByPathE path archive
77+ fname <- findEntryByPathE (root </> path) archive
78 return $ fixInternalReferences path .
78 return $ fixInternalReferences path .
79 readHtml os' .
79 readHtml os' .
80 UTF8.toStringLazy $
80 UTF8.toStringLazy $
81 fromEntry fname
81 fromEntry fname
82− mimeToReader s path
82+ mimeToReader s _ path
83 | s `elem` imageMimes = return $ imageToPandoc path
83 | s `elem` imageMimes = return $ imageToPandoc path
84 | otherwise = return $ mempty
84 | otherwise = return $ mempty
85
85