From eaf21c273d572e7300b6378f1279fb4695ab691d Mon Sep 17 00:00:00 2001 From: Nicole Rauch Date: Sat, 13 Aug 2016 22:51:06 +0200 Subject: Whitespace in certain kinds of string constants is no longer eliminated. --- src/Hakyll/Web/CompressCss.hs | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'src') 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) -- cgit v1.2.3