diff options
author | Nicole Rauch <nicole.m@gmx.de> | 2016-08-13 22:51:06 +0200 |
---|---|---|
committer | Nicole Rauch <nicole.m@gmx.de> | 2016-08-14 22:13:31 +0200 |
commit | eaf21c273d572e7300b6378f1279fb4695ab691d (patch) | |
tree | c4f883f4e59a3945c1dd8dbab4009c7c0d2f8e32 | |
parent | 66a90395fc1174d05254876d11698f4de5a895c2 (diff) | |
download | hakyll-eaf21c273d572e7300b6378f1279fb4695ab691d.tar.gz |
Whitespace in certain kinds of string constants is no longer eliminated.
-rw-r--r-- | src/Hakyll/Web/CompressCss.hs | 28 | ||||
-rw-r--r-- | tests/Hakyll/Web/CompressCss/Tests.hs | 3 |
2 files changed, 25 insertions, 6 deletions
diff --git a/src/Hakyll/Web/CompressCss.hs b/src/Hakyll/Web/CompressCss.hs index 58d52b4..ce7239f 100644 --- a/src/Hakyll/Web/CompressCss.hs +++ b/src/Hakyll/Web/CompressCss.hs @@ -33,16 +33,24 @@ compressCss = compressSeparators . stripComments . compressWhitespace -------------------------------------------------------------------------------- -- | Compresses certain forms of separators. compressSeparators :: String -> String -compressSeparators = - replaceAll "; *}" (const "}") . - replaceAll " *([{};]) *" (take 1 . dropWhile isSpace) . - replaceAll ";+" (const ";") - +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 -------------------------------------------------------------------------------- -- | Compresses all whitespace. compressWhitespace :: String -> String -compressWhitespace = replaceAll "[ \t\n\r]+" (const " ") +compressWhitespace [] = [] +compressWhitespace str + | isPrefixOf "\"" str = head str : retainConstants compressWhitespace "\"" (drop 1 str) + | isPrefixOf "'" str = head str : retainConstants compressWhitespace "'" (drop 1 str) + | otherwise = replaceAll "[ \t\n\r]+" (const " ") str -------------------------------------------------------------------------------- @@ -57,3 +65,11 @@ stripComments str | null str' = [] | isPrefixOf "*/" str' = drop 2 str' | otherwise = eatComments $ drop 1 str' + +-------------------------------------------------------------------------------- +-- | Helper function to handle string constants correctly. +retainConstants :: (String -> String) -> String -> String -> String +retainConstants f delim str + | null str = [] + | isPrefixOf delim str = head str : f (drop 1 str) + | otherwise = head str : retainConstants f delim (drop 1 str) diff --git a/tests/Hakyll/Web/CompressCss/Tests.hs b/tests/Hakyll/Web/CompressCss/Tests.hs index 1430abf..08c646d 100644 --- a/tests/Hakyll/Web/CompressCss/Tests.hs +++ b/tests/Hakyll/Web/CompressCss/Tests.hs @@ -33,6 +33,9 @@ tests = testGroup "Hakyll.Web.CompressCss.Tests" $ concat compressCss "; }" , "{};" @=? compressCss " { } ; " + -- but do not compress separators inside of constants + , "\" { } ; \"" @=? + compressCss "\" { } ; \"" , ";" @=? compressCss ";;;;;;;" |