diff options
author | John MacFarlane <jgm@berkeley.edu> | 2017-05-05 17:03:27 +0200 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2017-05-05 17:03:27 +0200 |
commit | c1b45adda09bae3c44e9e05832d54682696296c4 (patch) | |
tree | 592aba573a66af05f97447cb15779a1990cff72f /src/Text/Pandoc/SelfContained.hs | |
parent | 1668998c460be69fb5b26c3ba727c878394be331 (diff) |
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.
Diffstat (limited to 'src/Text/Pandoc/SelfContained.hs')
-rw-r--r-- | src/Text/Pandoc/SelfContained.hs | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/Text/Pandoc/SelfContained.hs b/src/Text/Pandoc/SelfContained.hs index 53cb4a4b5..6391ef0e0 100644 --- a/src/Text/Pandoc/SelfContained.hs +++ b/src/Text/Pandoc/SelfContained.hs @@ -178,12 +178,21 @@ pCSSUrl sourceURL d = P.try $ do P.char ')' let fallback = B.pack ("url(" ++ maybe "" (:[]) quote ++ trim url ++ 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 'd':'a':'t':'a':':':_ -> return fallback u -> do let url' = if isURI u then u else d </> u - enc <- lift $ getDataURI sourceURL "" url' - return (B.pack $ "url(" ++ enc ++ ")") + 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 ++ ")") getDataURI :: PandocMonad m => Maybe String -> MimeType -> String -> m String getDataURI sourceURL mimetype src = do |