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.
This commit is contained in:
parent
1668998c46
commit
c1b45adda0
1 changed files with 12 additions and 3 deletions
|
@ -178,11 +178,20 @@ pCSSUrl sourceURL d = P.try $ do
|
||||||
P.char ')'
|
P.char ')'
|
||||||
let fallback = B.pack ("url(" ++ maybe "" (:[]) quote ++ trim url ++
|
let fallback = B.pack ("url(" ++ maybe "" (:[]) quote ++ trim url ++
|
||||||
maybe "" (:[]) quote ++ ")")
|
maybe "" (:[]) quote ++ ")")
|
||||||
case trim url of
|
-- pipes are used in URLs provided by Google Code fonts
|
||||||
|
-- but parseURI doesn't like them, so we escape them:
|
||||||
|
case escapeURIString (/='|') (trim url) of
|
||||||
'#':_ -> return fallback
|
'#':_ -> return fallback
|
||||||
'd':'a':'t':'a':':':_ -> return fallback
|
'd':'a':'t':'a':':':_ -> return fallback
|
||||||
u -> do let url' = if isURI u then u else d </> u
|
u -> do let url' = if isURI u then u else d </> u
|
||||||
enc <- lift $ getDataURI sourceURL "" url'
|
res <- lift $ getData sourceURL "" url'
|
||||||
|
case res of
|
||||||
|
Left uri -> return (B.pack $ "url(" ++ uri ++ ")")
|
||||||
|
Right (mt, raw) -> do
|
||||||
|
-- note that the downloaded content may
|
||||||
|
-- itself contain url(...).
|
||||||
|
raw' <- cssURLs sourceURL d raw
|
||||||
|
let enc = makeDataURI (mt, raw')
|
||||||
return (B.pack $ "url(" ++ enc ++ ")")
|
return (B.pack $ "url(" ++ enc ++ ")")
|
||||||
|
|
||||||
getDataURI :: PandocMonad m => Maybe String -> MimeType -> String -> m String
|
getDataURI :: PandocMonad m => Maybe String -> MimeType -> String -> m String
|
||||||
|
|
Loading…
Reference in a new issue