summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Hakyll/Web/CompressCss.hs10
-rw-r--r--tests/Hakyll/Web/CompressCss/Tests.hs7
2 files changed, 15 insertions, 2 deletions
diff --git a/src/Hakyll/Web/CompressCss.hs b/src/Hakyll/Web/CompressCss.hs
index 23adce2..6667842 100644
--- a/src/Hakyll/Web/CompressCss.hs
+++ b/src/Hakyll/Web/CompressCss.hs
@@ -52,7 +52,15 @@ compressWhitespace [] = []
compressWhitespace str
| isPrefixOf "\"" str = head str : retainConstants compressWhitespace "\"" (drop 1 str)
| isPrefixOf "'" str = head str : retainConstants compressWhitespace "'" (drop 1 str)
- | otherwise = replaceAll "[ \t\n\r]+" (const " ") str
+ | isPrefixOf "\t" str = compressWhitespace (' ' : (drop 1 str))
+ | isPrefixOf "\n" str = compressWhitespace (' ' : (drop 1 str))
+ | isPrefixOf "\r" str = compressWhitespace (' ' : (drop 1 str))
+
+ | isPrefixOf " \t" str = compressWhitespace (' ' : (drop 2 str))
+ | isPrefixOf " \n" str = compressWhitespace (' ' : (drop 2 str))
+ | isPrefixOf " \r" str = compressWhitespace (' ' : (drop 2 str))
+ | isPrefixOf " " str = compressWhitespace (' ' : (drop 2 str))
+ | otherwise = head str : compressWhitespace (drop 1 str)
--------------------------------------------------------------------------------
diff --git a/tests/Hakyll/Web/CompressCss/Tests.hs b/tests/Hakyll/Web/CompressCss/Tests.hs
index 221aa82..065a588 100644
--- a/tests/Hakyll/Web/CompressCss/Tests.hs
+++ b/tests/Hakyll/Web/CompressCss/Tests.hs
@@ -23,6 +23,11 @@ tests = testGroup "Hakyll.Web.CompressCss.Tests" $ concat
-- compress whitespace
" something something " @=?
compressCss " something \n\t\r something "
+ -- do not compress whitespace in constants
+ , "abc \" \t\n\r \" xyz" @=?
+ compressCss "abc \" \t\n\r \" xyz"
+ , "abc ' \t\n\r ' xyz" @=?
+ compressCss "abc ' \t\n\r ' xyz"
-- strip comments
, "" @=? compressCss "/* abc { } ;; \n\t\r */"
@@ -40,7 +45,7 @@ tests = testGroup "Hakyll.Web.CompressCss.Tests" $ concat
-- don't get irritated by the wrong constant terminator
, "\" ' \"" @=? compressCss "\" ' \""
, "' \" '" @=? compressCss "' \" '"
- -- don't compress whitespace in constants in the middle of a string
+ -- don't compress whitespace around separators in constants in the middle of a string
, "abc '{ '" @=? compressCss "abc '{ '"
, "abc \"{ \"" @=? compressCss "abc \"{ \""
-- compress multiple semicolons