@@ -159,9 +159,10 @@ pCSSImport :: PandocMonad m => Maybe String -> FilePath
159pCSSImport sourceURL d = P.try $ do
159pCSSImport sourceURL d = P.try $ do
160 P.string "@import"
160 P.string "@import"
162− res <- pCSSUrl' sourceURL d
162+ res <- (pQuoted <|> pUrl) >>= handleCSSUrl sourceURL d
164− P.optional $ P.char ';' >> P.spaces
165 case res of
166 case res of
166 Left b -> return $ B.pack "@import " <> b
167 Left b -> return $ B.pack "@import " <> b
167 Right (_, b) -> return b
168 Right (_, b) -> return b
@@ -185,31 +186,44 @@ pCSSOther = do
185pCSSUrl :: PandocMonad m
186pCSSUrl :: PandocMonad m
186 => Maybe String -> FilePath -> ParsecT ByteString () m ByteString
187 => Maybe String -> FilePath -> ParsecT ByteString () m ByteString
187pCSSUrl sourceURL d = P.try $ do
188pCSSUrl sourceURL d = P.try $ do
188− res <- pCSSUrl' sourceURL d
189+ res <- pUrl >>= handleCSSUrl sourceURL d
189 case res of
190 case res of
190 Left b -> return b
191 Left b -> return b
191 Right (mt,b) -> do
192 Right (mt,b) -> do
192 let enc = makeDataURI (mt, b)
193 let enc = makeDataURI (mt, b)
193 return (B.pack $ "url(" ++ enc ++ ")")
194 return (B.pack $ "url(" ++ enc ++ ")")
195−pCSSUrl' :: PandocMonad m
196+pQuoted :: PandocMonad m
196− => Maybe String -> FilePath
197+ => ParsecT ByteString () m (String, ByteString)
199+ quote <- P.oneOf "\"'"
200+ url <- P.manyTill P.anyChar (P.char quote)
201+ let fallback = B.pack ([quote] ++ trim url ++ [quote])
202+ return (url, fallback)
204+pUrl :: PandocMonad m
197− -> ParsecT ByteString () m (Either ByteString (MimeType, ByteString))
205+ => ParsecT ByteString () m (String, ByteString)
198−pCSSUrl' sourceURL d = P.try $ do
206+pUrl = P.try $ do
199 P.string "url("
207 P.string "url("
201 quote <- P.option Nothing (Just <$> P.oneOf "\"'")
209 quote <- P.option Nothing (Just <$> P.oneOf "\"'")
202 url <- P.manyTill P.anyChar (maybe (P.lookAhead (P.char ')')) P.char quote)
210 url <- P.manyTill P.anyChar (maybe (P.lookAhead (P.char ')')) P.char quote)
204 P.char ')'
212 P.char ')'
205− let fallback = Left $
206− B.pack ("url(" ++ maybe "" (:[]) quote ++ trim url ++
213+ let fallback = B.pack ("url(" ++ maybe "" (:[]) quote ++ trim url ++
207 maybe "" (:[]) quote ++ ")")
214 maybe "" (:[]) quote ++ ")")
215+ return (url, fallback)
217+handleCSSUrl :: PandocMonad m
218+ => Maybe String -> FilePath -> (String, ByteString)
219+ -> ParsecT ByteString () m
220+ (Either ByteString (MimeType, ByteString))
221+handleCSSUrl sourceURL d (url, fallback) = do
208 -- pipes are used in URLs provided by Google Code fonts
222 -- pipes are used in URLs provided by Google Code fonts
209 -- but parseURI doesn't like them, so we escape them:
223 -- but parseURI doesn't like them, so we escape them:
210 case escapeURIString (/='|') (trim url) of
224 case escapeURIString (/='|') (trim url) of
211− '#':_ -> return fallback
225+ '#':_ -> return $ Left fallback
212− 'd':'a':'t':'a':':':_ -> return fallback
226+ 'd':'a':'t':'a':':':_ -> return $ Left fallback
213 u -> do let url' = if isURI u then u else d </> u
227 u -> do let url' = if isURI u then u else d </> u
214 res <- lift $ getData sourceURL "" url'
228 res <- lift $ getData sourceURL "" url'
215 case res of
229 case res of