diff --git a/src/Hakyll/Web/CompressCss.hs b/src/Hakyll/Web/CompressCss.hs index ce7239f..c00b5ee 100644 --- a/src/Hakyll/Web/CompressCss.hs +++ b/src/Hakyll/Web/CompressCss.hs @@ -37,11 +37,17 @@ compressSeparators [] = [] compressSeparators str | isPrefixOf "\"" str = head str : retainConstants compressSeparators "\"" (drop 1 str) | isPrefixOf "'" str = head str : retainConstants compressSeparators "'" (drop 1 str) - | otherwise = - replaceAll "; *}" (const "}") $ - replaceAll " *([{};]) *" (take 1 . dropWhile isSpace) $ - replaceAll ";+" (const ";") str - where + | isPrefixOf " " str = compressSeparators (drop 1 str) + | isPrefixOf " {" str = compressSeparators (drop 1 str) + | isPrefixOf " }" str = compressSeparators (drop 1 str) + | isPrefixOf " ;" str = compressSeparators (drop 1 str) + | isPrefixOf ";;" str = compressSeparators (drop 1 str) + | isPrefixOf "{ " str = compressSeparators (head str : (drop 2 str)) + | isPrefixOf "} " str = compressSeparators (head str : (drop 2 str)) + | isPrefixOf "; " str = compressSeparators (head str : (drop 2 str)) + | isPrefixOf ";}" str = '}' : compressSeparators (drop 2 str) + | otherwise = head str : compressSeparators (drop 1 str) + -------------------------------------------------------------------------------- -- | Compresses all whitespace. diff --git a/tests/Hakyll/Web/CompressCss/Tests.hs b/tests/Hakyll/Web/CompressCss/Tests.hs index c8db116..44dfc6c 100644 --- a/tests/Hakyll/Web/CompressCss/Tests.hs +++ b/tests/Hakyll/Web/CompressCss/Tests.hs @@ -46,11 +46,13 @@ tests = testGroup "Hakyll.Web.CompressCss.Tests" $ concat compressCss "\" ' \"" , "' \" '" @=? compressCss "' \" '" + -- don't compress whitespace in constants in the middle of a string + , "abc '{ '" @=? + compressCss "abc '{ '" + , "abc \"{ \"" @=? + compressCss "abc \"{ \"" + -- compress multiple semicolons , ";" @=? compressCss ";;;;;;;" - - -- some real-life css - , "a:after{content: \" (\" attr(href) \")\"}" @=? - compressCss "a:after { content: \" (\" attr(href) \")\"; }" ] ]