We need to constantly check whether we are at the start of a constant, not just once.

This commit is contained in:
Nicole Rauch 2016-08-14 19:23:10 +02:00
parent c0a86b3d7e
commit 0404185e83
2 changed files with 17 additions and 9 deletions

View File

@ -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.

View File

@ -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) \")\"; }"
]
]