summaryrefslogtreecommitdiff
path: root/src/Hakyll
diff options
context:
space:
mode:
authorNicole Rauch <nicole.m@gmx.de>2016-08-13 22:51:06 +0200
committerNicole Rauch <nicole.m@gmx.de>2016-08-14 22:13:31 +0200
commiteaf21c273d572e7300b6378f1279fb4695ab691d (patch)
treec4f883f4e59a3945c1dd8dbab4009c7c0d2f8e32 /src/Hakyll
parent66a90395fc1174d05254876d11698f4de5a895c2 (diff)
downloadhakyll-eaf21c273d572e7300b6378f1279fb4695ab691d.tar.gz
Whitespace in certain kinds of string constants is no longer eliminated.
Diffstat (limited to 'src/Hakyll')
-rw-r--r--src/Hakyll/Web/CompressCss.hs28
1 files changed, 22 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)