@@ -31,7 +31,6 @@ offline, by incorporating linked images, CSS, and scripts into
31the HTML using data URIs.
31the HTML using data URIs.
33module Text.Pandoc.SelfContained ( makeDataURI, makeSelfContained ) where
33module Text.Pandoc.SelfContained ( makeDataURI, makeSelfContained ) where
34−import Data.Monoid ((<>))
35import Codec.Compression.GZip as Gzip
34import Codec.Compression.GZip as Gzip
36import Control.Applicative ((<|>))
35import Control.Applicative ((<|>))
37import Control.Monad.Except (throwError)
36import Control.Monad.Except (throwError)
@@ -150,32 +149,7 @@ cssURLs sourceURL d orig = do
150parseCSSUrls :: PandocMonad m
149parseCSSUrls :: PandocMonad m
151 => Maybe String -> FilePath -> ParsecT ByteString () m ByteString
150 => Maybe String -> FilePath -> ParsecT ByteString () m ByteString
152parseCSSUrls sourceURL d = B.concat <$> P.many
151parseCSSUrls sourceURL d = B.concat <$> P.many
155− <|> pCSSImport sourceURL d
156− <|> (pCSSUrl >>= processCSSUrl sourceURL d)
152+ (pCSSWhite <|> pCSSComment <|> pCSSUrl sourceURL d <|> pCSSOther)
160−pCSSImport :: PandocMonad m
161− => Maybe String -> FilePath -> ParsecT ByteString () m ByteString
162−pCSSImport sourceURL d = P.try $ do
167− media <- P.manyTill P.anyChar (P.char ';')
168− let u = escapeURIString (/='|') (trim url)
169− let url' = if isURI u then u else d </> u
170− res <- lift $ getData sourceURL "" url'
172− Left uri -> return (B.pack $ "url(" ++ uri ++ ")")
173− Right (_, raw) -> do
174− raw' <- cssURLs sourceURL d raw
177− else return $ B.pack ("@media " ++ media ++ "{\n") <> raw' <>
180-- Note: some whitespace in CSS is significant, so we can't collapse it!
154-- Note: some whitespace in CSS is significant, so we can't collapse it!
181pCSSWhite :: PandocMonad m => ParsecT ByteString () m ByteString
155pCSSWhite :: PandocMonad m => ParsecT ByteString () m ByteString
@@ -194,21 +168,16 @@ pCSSOther = do
194 (B.singleton <$> P.char '/')
168 (B.singleton <$> P.char '/')
196pCSSUrl :: PandocMonad m
170pCSSUrl :: PandocMonad m
197− => ParsecT ByteString () m String
171+ => Maybe String -> FilePath -> ParsecT ByteString () m ByteString
198−pCSSUrl = P.try $ do
172+pCSSUrl sourceURL d = P.try $ do
199 P.string "url("
173 P.string "url("
201 quote <- P.option Nothing (Just <$> P.oneOf "\"'")
175 quote <- P.option Nothing (Just <$> P.oneOf "\"'")
202 url <- P.manyTill P.anyChar (maybe (P.lookAhead (P.char ')')) P.char quote)
176 url <- P.manyTill P.anyChar (maybe (P.lookAhead (P.char ')')) P.char quote)
204 P.char ')'
178 P.char ')'
207−processCSSUrl :: PandocMonad m
208− => Maybe String -> FilePath -> String
209− -> ParsecT ByteString () m ByteString
210−processCSSUrl sourceURL d url = do
211− let fallback = B.pack ("url('" ++ trim url ++ "')")
179+ let fallback = B.pack ("url(" ++ maybe "" (:[]) quote ++ trim url ++
180+ maybe "" (:[]) quote ++ ")")
212 -- pipes are used in URLs provided by Google Code fonts
181 -- pipes are used in URLs provided by Google Code fonts
213 -- but parseURI doesn't like them, so we escape them:
182 -- but parseURI doesn't like them, so we escape them:
214 case escapeURIString (/='|') (trim url) of
183 case escapeURIString (/='|') (trim url) of