on master help sign in
We need to constantly check whether we are at the start of a constant, not just once.
commit0404185e835fb11bec70882b695df7b53c3dd451 authorNicole Rauch <nicole.m@gmx.de> dateSun 14 Aug 2016, 19:23 (10 years ago) parentc0a86b3
2 files changed+17−9
src/Hakyll/Web/CompressCss.hs+11−5 tests/Hakyll/Web/CompressCss/Tests.hs+6−4
src/Hakyll/Web/CompressCss.hs+11−5
@@ -37,11 +37,17 @@ compressSeparators [] = []
3737compressSeparators str
3838 | isPrefixOf "\"" str = head str : retainConstants compressSeparators "\"" (drop 1 str)
3939 | isPrefixOf "'" str = head str : retainConstants compressSeparators "'" (drop 1 str)
40− | otherwise =
41− replaceAll "; *}" (const "}") $
42− replaceAll " *([{};]) *" (take 1 . dropWhile isSpace) $
43− replaceAll ";+" (const ";") str
44− where
40+ | isPrefixOf " " str = compressSeparators (drop 1 str)
41+ | isPrefixOf " {" str = compressSeparators (drop 1 str)
42+ | isPrefixOf " }" str = compressSeparators (drop 1 str)
43+ | isPrefixOf " ;" str = compressSeparators (drop 1 str)
44+ | isPrefixOf ";;" str = compressSeparators (drop 1 str)
45+ | isPrefixOf "{ " str = compressSeparators (head str : (drop 2 str))
46+ | isPrefixOf "} " str = compressSeparators (head str : (drop 2 str))
47+ | isPrefixOf "; " str = compressSeparators (head str : (drop 2 str))
48+ | isPrefixOf ";}" str = '}' : compressSeparators (drop 2 str)
49+ | otherwise = head str : compressSeparators (drop 1 str)
50+
4551
4652--------------------------------------------------------------------------------
4753-- | Compresses all whitespace.
tests/Hakyll/Web/CompressCss/Tests.hs+6−4
@@ -46,11 +46,13 @@ tests = testGroup "Hakyll.Web.CompressCss.Tests" $ concat
4646 compressCss "\" ' \""
4747 , "' \" '" @=?
4848 compressCss "' \" '"
49+ -- don't compress whitespace in constants in the middle of a string
50+ , "abc '{ '" @=?
51+ compressCss "abc '{ '"
52+ , "abc \"{ \"" @=?
53+ compressCss "abc \"{ \""
54+ -- compress multiple semicolons
4955 , ";" @=?
5056 compressCss ";;;;;;;"
51−
52− -- some real-life css
53− , "a:after{content: \" (\" attr(href) \")\"}" @=?
54− compressCss "a:after { content: \" (\" attr(href) \")\"; }"
5557 ]
5658 ]