@@ -51,7 +51,7 @@ runEPUB = either error id . runExcept
51-- are of the form "filename#id"
51-- are of the form "filename#id"
53archiveToEPUB :: (MonadError String m) => ReaderOptions -> Archive -> m (Pandoc, MediaBag)
53archiveToEPUB :: (MonadError String m) => ReaderOptions -> Archive -> m (Pandoc, MediaBag)
54−archiveToEPUB os archive = do
54+archiveToEPUB (setEPUBOptions -> os) archive = do
55 (root, content) <- getManifest archive
55 (root, content) <- getManifest archive
56 meta <- parseMeta content
56 meta <- parseMeta content
57 (cover, items) <- parseManifest content
57 (cover, items) <- parseManifest content
@@ -65,9 +65,6 @@ archiveToEPUB os archive = do
65 let mediaBag = fetchImages (M.elems items) root archive ast
65 let mediaBag = fetchImages (M.elems items) root archive ast
66 return $ (ast, mediaBag)
66 return $ (ast, mediaBag)
68− rs = readerExtensions os
69− os' = os {readerExtensions = foldr S.insert rs [Ext_epub_html_exts, Ext_raw_html]}
70− os'' = os' {readerParseRaw = True}
71 parseSpineElem :: MonadError String m => FilePath -> (FilePath, MIME) -> m Pandoc
68 parseSpineElem :: MonadError String m => FilePath -> (FilePath, MIME) -> m Pandoc
72 parseSpineElem (normalise -> r) (normalise -> path, mime) = do
69 parseSpineElem (normalise -> r) (normalise -> path, mime) = do
73 when (readerTrace os) (traceM path)
70 when (readerTrace os) (traceM path)
@@ -78,13 +75,20 @@ archiveToEPUB os archive = do
78 mimeToReader "application/xhtml+xml" r path = do
75 mimeToReader "application/xhtml+xml" r path = do
79 fname <- findEntryByPathE (r </> path) archive
76 fname <- findEntryByPathE (r </> path) archive
80 return $ fixInternalReferences (r </> path) .
77 return $ fixInternalReferences (r </> path) .
81− readHtml os'' .
78+ readHtml os .
82 UTF8.toStringLazy $
79 UTF8.toStringLazy $
83 fromEntry fname
80 fromEntry fname
84 mimeToReader s _ path
81 mimeToReader s _ path
85 | s `elem` imageMimes = return $ imageToPandoc path
82 | s `elem` imageMimes = return $ imageToPandoc path
86 | otherwise = return $ mempty
83 | otherwise = return $ mempty
85+setEPUBOptions :: ReaderOptions -> ReaderOptions
86+setEPUBOptions os = os''
88+ rs = readerExtensions os
89+ os' = os {readerExtensions = foldr S.insert rs [Ext_epub_html_exts]}
90+ os'' = os' {readerParseRaw = True}
88fetchImages :: [(FilePath, MIME)]
92fetchImages :: [(FilePath, MIME)]
89 -> FilePath
93 -> FilePath
90 -> Archive
94 -> Archive