summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/SelfContained.hs
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-05-05 23:23:49 +0200
committerJohn MacFarlane <jgm@berkeley.edu>2017-05-05 23:23:49 +0200
commit9f0a80457fb0ab343af651af8c7bc6f9dc467f55 (patch)
tree592aba573a66af05f97447cb15779a1990cff72f /src/Text/Pandoc/SelfContained.hs
parent89b3fcc8e050def3779fed716d70bfd4e7120a6b (diff)
Revert "SelfContained: special handling for css @import."
This reverts commit 89b3fcc8e050def3779fed716d70bfd4e7120a6b.
Diffstat (limited to 'src/Text/Pandoc/SelfContained.hs')
-rw-r--r--src/Text/Pandoc/SelfContained.hs41
1 files changed, 5 insertions, 36 deletions
diff --git a/src/Text/Pandoc/SelfContained.hs b/src/Text/Pandoc/SelfContained.hs
index a5ae0a929..6391ef0e0 100644
--- a/src/Text/Pandoc/SelfContained.hs
+++ b/src/Text/Pandoc/SelfContained.hs
@@ -31,7 +31,6 @@ offline, by incorporating linked images, CSS, and scripts into
the HTML using data URIs.
-}
module Text.Pandoc.SelfContained ( makeDataURI, makeSelfContained ) where
-import Data.Monoid ((<>))
import Codec.Compression.GZip as Gzip
import Control.Applicative ((<|>))
import Control.Monad.Except (throwError)
@@ -150,32 +149,7 @@ cssURLs sourceURL d orig = do
parseCSSUrls :: PandocMonad m
=> Maybe String -> FilePath -> ParsecT ByteString () m ByteString
parseCSSUrls sourceURL d = B.concat <$> P.many
- ( pCSSWhite
- <|> pCSSComment
- <|> pCSSImport sourceURL d
- <|> (pCSSUrl >>= processCSSUrl sourceURL d)
- <|> pCSSOther
- )
-
-pCSSImport :: PandocMonad m
- => Maybe String -> FilePath -> ParsecT ByteString () m ByteString
-pCSSImport sourceURL d = P.try $ do
- P.string "@import"
- P.spaces
- url <- pCSSUrl
- P.spaces
- media <- P.manyTill P.anyChar (P.char ';')
- let u = escapeURIString (/='|') (trim url)
- let url' = if isURI u then u else d </> u
- res <- lift $ getData sourceURL "" url'
- case res of
- Left uri -> return (B.pack $ "url(" ++ uri ++ ")")
- Right (_, raw) -> do
- raw' <- cssURLs sourceURL d raw
- if null media
- then return raw'
- else return $ B.pack ("@media " ++ media ++ "{\n") <> raw' <>
- B.pack "}"
+ (pCSSWhite <|> pCSSComment <|> pCSSUrl sourceURL d <|> pCSSOther)
-- Note: some whitespace in CSS is significant, so we can't collapse it!
pCSSWhite :: PandocMonad m => ParsecT ByteString () m ByteString
@@ -194,21 +168,16 @@ pCSSOther = do
(B.singleton <$> P.char '/')
pCSSUrl :: PandocMonad m
- => ParsecT ByteString () m String
-pCSSUrl = P.try $ do
+ => Maybe String -> FilePath -> ParsecT ByteString () m ByteString
+pCSSUrl sourceURL d = P.try $ do
P.string "url("
P.spaces
quote <- P.option Nothing (Just <$> P.oneOf "\"'")
url <- P.manyTill P.anyChar (maybe (P.lookAhead (P.char ')')) P.char quote)
P.spaces
P.char ')'
- return url
-
-processCSSUrl :: PandocMonad m
- => Maybe String -> FilePath -> String
- -> ParsecT ByteString () m ByteString
-processCSSUrl sourceURL d url = do
- let fallback = B.pack ("url('" ++ trim url ++ "')")
+ let fallback = B.pack ("url(" ++ maybe "" (:[]) quote ++ trim url ++
+ maybe "" (:[]) quote ++ ")")
-- 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