git.iko.soy/typeable/pandoc
on master help sign in
EPUB reader: unescape URIs in spine.
8471678John MacFarlane
src/Text/Pandoc/Readers/EPUB.hs+4−2
@@ -14,6 +14,7 @@ import Text.Pandoc.Walk (walk, query)
14import Text.Pandoc.Readers.HTML (readHtml)
14import Text.Pandoc.Readers.HTML (readHtml)
15import Text.Pandoc.Options ( ReaderOptions(..), readerTrace)
15import Text.Pandoc.Options ( ReaderOptions(..), readerTrace)
16import Text.Pandoc.Shared (escapeURI, collapseFilePath, addMetaField)
16import Text.Pandoc.Shared (escapeURI, collapseFilePath, addMetaField)
17+import Network.URI (unEscapeString)
17import Text.Pandoc.MediaBag (MediaBag, insertMedia)
18import Text.Pandoc.MediaBag (MediaBag, insertMedia)
18import Text.Pandoc.Compat.Except (MonadError, throwError, runExcept, Except)
19import Text.Pandoc.Compat.Except (MonadError, throwError, runExcept, Except)
19import Text.Pandoc.Compat.Monoid ((<>))
20import Text.Pandoc.Compat.Monoid ((<>))
@@ -74,14 +75,15 @@ archiveToEPUB os archive = do
74 let docSpan = B.doc $ B.para $ B.spanWith (takeFileName path, [], []) mempty
75 let docSpan = B.doc $ B.para $ B.spanWith (takeFileName path, [], []) mempty
75 return $ docSpan <> doc
76 return $ docSpan <> doc
76 mimeToReader :: MonadError PandocError m => MimeType -> FilePath -> FilePath -> m Pandoc
77 mimeToReader :: MonadError PandocError m => MimeType -> FilePath -> FilePath -> m Pandoc
77− mimeToReader "application/xhtml+xml" (normalise -> root) (normalise -> path) = do
78+ mimeToReader "application/xhtml+xml" (unEscapeString -> root)
79+ (unEscapeString -> path) = do
78 fname <- findEntryByPathE (root </> path) archive
80 fname <- findEntryByPathE (root </> path) archive
79 html <- either throwError return .
81 html <- either throwError return .
80 readHtml os' .
82 readHtml os' .
81 UTF8.toStringLazy $
83 UTF8.toStringLazy $
82 fromEntry fname
84 fromEntry fname
83 return $ fixInternalReferences path html
85 return $ fixInternalReferences path html
84− mimeToReader s _ path
86+ mimeToReader s _ (unEscapeString -> path)
85 | s `elem` imageMimes = return $ imageToPandoc path
87 | s `elem` imageMimes = return $ imageToPandoc path
86 | otherwise = return $ mempty
88 | otherwise = return $ mempty
87
89