git.iko.soy/typeable/pandoc
on master help sign in
EPUB writer: Don't add sourceURL to absolute URIs!

Closes #1669. If there are further issues, please open a new, targeted issue on the tracker. Some notes on the further issues you gestured at: Data URIs are indeed dereferenced, but why is this a problem? (The function being used to fetch from URLs is used for many different formats. Preserving data URIs would make sense in EPUBs, but not for e.g. PDF output. And by dereferencing we can get a smaller, more efficient EPUB, with the data stored as bytes in a file rather than encoded in textual representation.) "absolute uris are not recognized" -- I assume that is the problem just fixed. If not, please open a new issue. "relative uris are resolved (wrongly) like file paths" -- can you give an example? `<base>` tag is ignored. Yes. I didn't know about the base tag. Could you open a new issue just for this?

commitd60707eed046979a68b51f03a02ae6163c63a4ac authorJohn MacFarlane <jgm@berkeley.edu> dateWed 8 Oct 2014, 11:52 (12 years ago) parentccd04ad
1 file changed+10−5
src/Text/Pandoc/Writers/EPUB.hs+10−5
src/Text/Pandoc/Writers/EPUB.hs+10−5
@@ -64,7 +64,7 @@ import Text.XML.Light ( unode, Element(..), unqual, Attr(..), add_attrs
6464import Text.Pandoc.UUID (getRandomUUID)
6565import Text.Pandoc.Writers.HTML (writeHtmlString, writeHtml)
6666import Data.Char ( toLower, isDigit, isAlphaNum )
67−import Network.URI ( unEscapeString )
67+import Network.URI ( unEscapeString, isURI )
6868import Text.Pandoc.MIME (MimeType, getMimeType)
6969import qualified Control.Exception as E
7070import Text.Blaze.Html.Renderer.Utf8 (renderHtml)
@@ -773,8 +773,12 @@ transformTag opts mediaRef tag@(TagOpen name attr)
773773 | name `elem` ["video", "source", "img", "audio"] = do
774774 let src = fromAttrib "src" tag
775775 let poster = fromAttrib "poster" tag
776− let oldsrc = maybe src (</> src) $ writerSourceURL opts
777− let oldposter = maybe poster (</> poster) $ writerSourceURL opts
776+ let oldsrc = case writerSourceURL opts of
777+ Just u | not (isURI src) -> u </> src
778+ _ -> src
779+ let oldposter = case writerSourceURL opts of
780+ Just u | not (isURI src) -> u </> poster
781+ _ -> poster
778782 newsrc <- modifyMediaRef mediaRef oldsrc
779783 newposter <- modifyMediaRef mediaRef oldposter
780784 let attr' = filter (\(x,_) -> x /= "src" && x /= "poster") attr ++
@@ -811,8 +815,9 @@ transformInline :: WriterOptions
811815 -> Inline
812816 -> IO Inline
813817transformInline opts mediaRef (Image lab (src,tit)) = do
814− let src' = unEscapeString src
815− let oldsrc = maybe src' (</> src) $ writerSourceURL opts
818+ let oldsrc = case (unEscapeString src, writerSourceURL opts) of
819+ (s, Just u) | not (isURI s) -> u </> s
820+ (s, _) -> s
816821 newsrc <- modifyMediaRef mediaRef oldsrc
817822 return $ Image lab (newsrc, tit)
818823transformInline opts _ (x@(Math _ _))