summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Hakyll/Web/CompressCss.hs13
-rw-r--r--tests/Hakyll/Web/CompressCss/Tests.hs10
2 files changed, 14 insertions, 9 deletions
diff --git a/src/Hakyll/Web/CompressCss.hs b/src/Hakyll/Web/CompressCss.hs
index 0371d8b..9f61534 100644
--- a/src/Hakyll/Web/CompressCss.hs
+++ b/src/Hakyll/Web/CompressCss.hs
@@ -33,14 +33,15 @@ compressCss = compressSeparators . stripComments . compressWhitespace
compressSeparators :: String -> String
compressSeparators [] = []
compressSeparators str
- | isConstant = head str : retainConstants compressSeparators (head str) (drop 1 str)
+ | isConstant = head str : retainConstants compressSeparators (head str) (drop 1 str)
| stripFirst = compressSeparators (drop 1 str)
| stripSecond = compressSeparators (head str : (drop 2 str))
| otherwise = head str : compressSeparators (drop 1 str)
where
isConstant = or $ map (isOfPrefix str) ["\"", "'"]
- stripFirst = or $ map (isOfPrefix str) [" ", " {", " }", " :", ";;", ";}"]
- stripSecond = or $ map (isOfPrefix str) ["{ ", "} ", ": ", "; "]
+ stripFirst = or $ map (isOfPrefix str) $ [";;", ";}"] ++ (map (\c -> " " ++ c) separators)
+ stripSecond = or $ map (isOfPrefix str) $ map (\c -> c ++ " ") separators
+ separators = [" ", "{", "}", ":", ";", ",", ">", "+", "!"]
--------------------------------------------------------------------------------
-- | Compresses all whitespace.
@@ -50,7 +51,7 @@ compressWhitespace str
| isConstant = head str : retainConstants compressWhitespace (head str) (drop 1 str)
| replaceOne = compressWhitespace (' ' : (drop 1 str))
| replaceTwo = compressWhitespace (' ' : (drop 2 str))
- | otherwise = head str : compressWhitespace (drop 1 str)
+ | otherwise = head str : compressWhitespace (drop 1 str)
where
isConstant = or $ map (isOfPrefix str) ["\"", "'"]
replaceOne = or $ map (isOfPrefix str) ["\t", "\n", "\r"]
@@ -61,9 +62,9 @@ compressWhitespace str
stripComments :: String -> String
stripComments [] = []
stripComments str
- | isConstant = head str : retainConstants stripComments (head str) (drop 1 str)
+ | isConstant = head str : retainConstants stripComments (head str) (drop 1 str)
| isPrefixOf "/*" str = stripComments $ eatComments $ drop 2 str
- | otherwise = head str : stripComments (drop 1 str)
+ | otherwise = head str : stripComments (drop 1 str)
where
isConstant = or $ map (isOfPrefix str) ["\"", "'"]
eatComments str'
diff --git a/tests/Hakyll/Web/CompressCss/Tests.hs b/tests/Hakyll/Web/CompressCss/Tests.hs
index 8521014..7420e4c 100644
--- a/tests/Hakyll/Web/CompressCss/Tests.hs
+++ b/tests/Hakyll/Web/CompressCss/Tests.hs
@@ -37,11 +37,15 @@ tests = testGroup "Hakyll.Web.CompressCss.Tests" $ concat
-- compress separators
, "}" @=? compressCss "; }"
- , "{};" @=? compressCss " { } ; "
+ , ";{};" @=? compressCss " ; { } ; "
+ , "text," @=? compressCss "text , "
+ , "a>b" @=? compressCss "a > b"
+ , "a+b" @=? compressCss "a + b"
+ , "a!b" @=? compressCss "a ! b"
-- compress whitespace even after this curly brace
, "}" @=? compressCss "; } "
-- but do not compress separators inside of constants
- , "\" { } ; \"" @=? compressCss "\" { } ; \""
+ , "\" { } ; , \"" @=? compressCss "\" { } ; , \""
-- don't compress separators at the start or end of constants
, "\" }\"" @=? compressCss "\" }\""
, "\"{ \"" @=? compressCss "\"{ \""
@@ -51,7 +55,7 @@ tests = testGroup "Hakyll.Web.CompressCss.Tests" $ concat
-- don't compress whitespace around separators in constants in the middle of a string
, "abc '{ '" @=? compressCss "abc '{ '"
, "abc \"{ \"" @=? compressCss "abc \"{ \""
- -- compress whitespace after colons
+ -- compress whitespace around colons
, "abc:xyz" @=? compressCss "abc : xyz"
-- compress multiple semicolons
, ";" @=? compressCss ";;;;;;;"