git.iko.soy/typeable/pandoc
on master help sign in
SelfContained: Handle url() inside material retrieved from url().

This can happen e.g. with an @import of a google web font. (What is imported is some CSS which contains an url reference to the font itself.) Also, allow unescaped pipe (|) in URL. This is intended to help with #3629, but it doesn't seem to work.

commitc1b45adda09bae3c44e9e05832d54682696296c4 authorJohn MacFarlane <jgm@berkeley.edu> dateFri 5 May 2017, 17:03 (10 years ago) parent1668998
1 file changed+12−3
src/Text/Pandoc/SelfContained.hs+12−3
src/Text/Pandoc/SelfContained.hs+12−3
@@ -178,12 +178,21 @@ pCSSUrl sourceURL d = P.try $ do
178178 P.char ')'
179179 let fallback = B.pack ("url(" ++ maybe "" (:[]) quote ++ trim url ++
180180 maybe "" (:[]) quote ++ ")")
181− case trim url of
181+ -- pipes are used in URLs provided by Google Code fonts
182+ -- but parseURI doesn't like them, so we escape them:
183+ case escapeURIString (/='|') (trim url) of
182184 '#':_ -> return fallback
183185 'd':'a':'t':'a':':':_ -> return fallback
184186 u -> do let url' = if isURI u then u else d </> u
185− enc <- lift $ getDataURI sourceURL "" url'
186− return (B.pack $ "url(" ++ enc ++ ")")
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')
195+ return (B.pack $ "url(" ++ enc ++ ")")
187196
188197getDataURI :: PandocMonad m => Maybe String -> MimeType -> String -> m String
189198getDataURI sourceURL mimetype src = do