on master help sign in
Whitespace in certain kinds of string constants is no longer eliminated.
eaf21c2Nicole Rauch
src/Hakyll/Web/CompressCss.hs+22−6
@@ -33,16 +33,24 @@ compressCss = compressSeparators . stripComments . compressWhitespace
33--------------------------------------------------------------------------------
33--------------------------------------------------------------------------------
34-- | Compresses certain forms of separators.
34-- | Compresses certain forms of separators.
35compressSeparators :: String -> String
35compressSeparators :: String -> String
36−compressSeparators =
36+compressSeparators [] = []
37+compressSeparators str
38+ | isPrefixOf "\"" str = head str : retainConstants compressSeparators "\"" (drop 1 str)
39+ | isPrefixOf "'" str = head str : retainConstants compressSeparators "'" (drop 1 str)
40+ | otherwise =
37− replaceAll "; *}" (const "}") .
41+ replaceAll "; *}" (const "}") $
38− replaceAll " *([{};]) *" (take 1 . dropWhile isSpace) .
42+ replaceAll " *([{};]) *" (take 1 . dropWhile isSpace) $
39− replaceAll ";+" (const ";")
43+ replaceAll ";+" (const ";") str
40−
44+ where
41
45
42--------------------------------------------------------------------------------
46--------------------------------------------------------------------------------
43-- | Compresses all whitespace.
47-- | Compresses all whitespace.
44compressWhitespace :: String -> String
48compressWhitespace :: String -> String
45−compressWhitespace = replaceAll "[ \t\n\r]+" (const " ")
49+compressWhitespace [] = []
50+compressWhitespace str
51+ | isPrefixOf "\"" str = head str : retainConstants compressWhitespace "\"" (drop 1 str)
52+ | isPrefixOf "'" str = head str : retainConstants compressWhitespace "'" (drop 1 str)
53+ | otherwise = replaceAll "[ \t\n\r]+" (const " ") str
46
54
47
55
48--------------------------------------------------------------------------------
56--------------------------------------------------------------------------------
@@ -57,3 +65,11 @@ stripComments str
57 | null str' = []
65 | null str' = []
58 | isPrefixOf "*/" str' = drop 2 str'
66 | isPrefixOf "*/" str' = drop 2 str'
59 | otherwise = eatComments $ drop 1 str'
67 | otherwise = eatComments $ drop 1 str'
68+
69+--------------------------------------------------------------------------------
70+-- | Helper function to handle string constants correctly.
71+retainConstants :: (String -> String) -> String -> String -> String
72+retainConstants f delim str
73+ | null str = []
74+ | isPrefixOf delim str = head str : f (drop 1 str)
75+ | otherwise = head str : retainConstants f delim (drop 1 str)
tests/Hakyll/Web/CompressCss/Tests.hs+3
@@ -33,6 +33,9 @@ tests = testGroup "Hakyll.Web.CompressCss.Tests" $ concat
33 compressCss "; }"
33 compressCss "; }"
34 , "{};" @=?
34 , "{};" @=?
35 compressCss " { } ; "
35 compressCss " { } ; "
36+ -- but do not compress separators inside of constants
37+ , "\" { } ; \"" @=?
38+ compressCss "\" { } ; \""
36 , ";" @=?
39 , ";" @=?
37 compressCss ";;;;;;;"
40 compressCss ";;;;;;;"
38
41