on master help sign in
We must avoid the compression of whitespace in constants by handling it in the same way.
commite70605dfe681dbc0f79e0a8f426ac6c9fc9820a9 authorNicole Rauch <nicole.m@gmx.de> dateSun 14 Aug 2016, 19:51 (10 years ago) parent8f11bbd
2 files changed+15−2
src/Hakyll/Web/CompressCss.hs+9−1 tests/Hakyll/Web/CompressCss/Tests.hs+6−1
src/Hakyll/Web/CompressCss.hs+9−1
@@ -52,7 +52,15 @@ compressWhitespace [] = []
5252compressWhitespace str
5353 | isPrefixOf "\"" str = head str : retainConstants compressWhitespace "\"" (drop 1 str)
5454 | 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)
5664
5765
5866--------------------------------------------------------------------------------
tests/Hakyll/Web/CompressCss/Tests.hs+6−1
@@ -23,6 +23,11 @@ tests = testGroup "Hakyll.Web.CompressCss.Tests" $ concat
2323 -- compress whitespace
2424 " something something " @=?
2525 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"
2631
2732 -- strip comments
2833 , "" @=? compressCss "/* abc { } ;; \n\t\r */"
@@ -40,7 +45,7 @@ tests = testGroup "Hakyll.Web.CompressCss.Tests" $ concat
4045 -- don't get irritated by the wrong constant terminator
4146 , "\" ' \"" @=? compressCss "\" ' \""
4247 , "' \" '" @=? 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
4449 , "abc '{ '" @=? compressCss "abc '{ '"
4550 , "abc \"{ \"" @=? compressCss "abc \"{ \""
4651 -- compress multiple semicolons