git.iko.soy/typeable/pandoc
on master help sign in
SelfContained: Handle url() inside material retrieved from url().
c1b45adJohn MacFarlane
src/Text/Pandoc/SelfContained.hs+12−3
@@ -178,12 +178,21 @@ pCSSUrl sourceURL d = P.try $ do
178 P.char ')'
178 P.char ')'
179 let fallback = B.pack ("url(" ++ maybe "" (:[]) quote ++ trim url ++
179 let fallback = B.pack ("url(" ++ maybe "" (:[]) quote ++ trim url ++
180 maybe "" (:[]) quote ++ ")")
180 maybe "" (:[]) quote ++ ")")
181+ -- pipes are used in URLs provided by Google Code fonts
182+ -- but parseURI doesn't like them, so we escape them:
181− case trim url of
183+ case escapeURIString (/='|') (trim url) of
182 '#':_ -> return fallback
184 '#':_ -> return fallback
183 'd':'a':'t':'a':':':_ -> return fallback
185 'd':'a':'t':'a':':':_ -> return fallback
184 u -> do let url' = if isURI u then u else d </> u
186 u -> do let url' = if isURI u then u else d </> u
185− enc <- lift $ getDataURI sourceURL "" url'
187+ res <- lift $ getData sourceURL "" url'
188+ case res of
189+ Left uri -> return (B.pack $ "url(" ++ uri ++ ")")
190+ Right (mt, raw) -> do
191+ -- note that the downloaded content may
192+ -- itself contain url(...).
193+ raw' <- cssURLs sourceURL d raw
194+ let enc = makeDataURI (mt, raw')
186− return (B.pack $ "url(" ++ enc ++ ")")
195+ return (B.pack $ "url(" ++ enc ++ ")")
187
196
188getDataURI :: PandocMonad m => Maybe String -> MimeType -> String -> m String
197getDataURI :: PandocMonad m => Maybe String -> MimeType -> String -> m String
189getDataURI sourceURL mimetype src = do
198getDataURI sourceURL mimetype src = do