Skip to content

Commit

Permalink
We need to constantly check whether we are at the start of a constant…
Browse files Browse the repository at this point in the history
…, not just once.
  • Loading branch information
NicoleRauch committed Aug 14, 2016
1 parent c0a86b3 commit 0404185
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
16 changes: 11 additions & 5 deletions src/Hakyll/Web/CompressCss.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 6 additions & 4 deletions tests/Hakyll/Web/CompressCss/Tests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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) \")\"; }"
]
]

0 comments on commit 0404185

Please sign in to comment.