on master help sign in
We must avoid the compression of whitespace in constants by handling it in the same way.
e70605dNicole Rauch
src/Hakyll/Web/CompressCss.hs+9−1
@@ -52,7 +52,15 @@ compressWhitespace [] = []
52compressWhitespace str
52compressWhitespace str
53 | isPrefixOf "\"" str = head str : retainConstants compressWhitespace "\"" (drop 1 str)
53 | isPrefixOf "\"" str = head str : retainConstants compressWhitespace "\"" (drop 1 str)
54 | isPrefixOf "'" str = head str : retainConstants compressWhitespace "'" (drop 1 str)
54 | isPrefixOf "'" str = head str : retainConstants compressWhitespace "'" (drop 1 str)
55− | otherwise = replaceAll "[ \t\n\r]+" (const " ") str
55+ | isPrefixOf "\t" str = compressWhitespace (' ' : (drop 1 str))
56+ | isPrefixOf "\n" str = compressWhitespace (' ' : (drop 1 str))
57+ | isPrefixOf "\r" str = compressWhitespace (' ' : (drop 1 str))
58+
59+ | isPrefixOf " \t" str = compressWhitespace (' ' : (drop 2 str))
60+ | isPrefixOf " \n" str = compressWhitespace (' ' : (drop 2 str))
61+ | isPrefixOf " \r" str = compressWhitespace (' ' : (drop 2 str))
62+ | isPrefixOf " " str = compressWhitespace (' ' : (drop 2 str))
63+ | otherwise = head str : compressWhitespace (drop 1 str)
56
64
57
65
58--------------------------------------------------------------------------------
66--------------------------------------------------------------------------------
tests/Hakyll/Web/CompressCss/Tests.hs+6−1
@@ -23,6 +23,11 @@ tests = testGroup "Hakyll.Web.CompressCss.Tests" $ concat
23 -- compress whitespace
23 -- compress whitespace
24 " something something " @=?
24 " something something " @=?
25 compressCss " something \n\t\r something "
25 compressCss " something \n\t\r something "
26+ -- do not compress whitespace in constants
27+ , "abc \" \t\n\r \" xyz" @=?
28+ compressCss "abc \" \t\n\r \" xyz"
29+ , "abc ' \t\n\r ' xyz" @=?
30+ compressCss "abc ' \t\n\r ' xyz"
26
31
27 -- strip comments
32 -- strip comments
28 , "" @=? compressCss "/* abc { } ;; \n\t\r */"
33 , "" @=? compressCss "/* abc { } ;; \n\t\r */"
@@ -40,7 +45,7 @@ tests = testGroup "Hakyll.Web.CompressCss.Tests" $ concat
40 -- don't get irritated by the wrong constant terminator
45 -- don't get irritated by the wrong constant terminator
41 , "\" ' \"" @=? compressCss "\" ' \""
46 , "\" ' \"" @=? compressCss "\" ' \""
42 , "' \" '" @=? compressCss "' \" '"
47 , "' \" '" @=? compressCss "' \" '"
43− -- don't compress whitespace in constants in the middle of a string
48+ -- don't compress whitespace around separators in constants in the middle of a string
44 , "abc '{ '" @=? compressCss "abc '{ '"
49 , "abc '{ '" @=? compressCss "abc '{ '"
45 , "abc \"{ \"" @=? compressCss "abc \"{ \""
50 , "abc \"{ \"" @=? compressCss "abc \"{ \""
46 -- compress multiple semicolons
51 -- compress multiple semicolons