on master help sign in
Merge pull request #75 from sphynx/master

Added Windows newlines (\r\n) support to the page parser and CSS compressor

commitf85cee026f44385c018c673f5c75122306a31ee0 authorJasper Van der Jeugt <jaspervdj@gmail.com> dateThu 2 Aug 2012, 07:17 (14 years ago) parent763eeb9e3b2d07
2 files changed+9−4
src/Hakyll/Web/CompressCss.hs+2−2 src/Hakyll/Web/Page/Read.hs+7−2
src/Hakyll/Web/CompressCss.hs+2−2
@@ -31,12 +31,12 @@ compressCss = compressSeparators
3131compressSeparators :: String -> String
3232compressSeparators = replaceAll "; *}" (const "}")
3333 . replaceAll " *([{};:]) *" (take 1 . dropWhile isSpace)
34− . replaceAll ";;*" (const ";")
34+ . replaceAll ";+" (const ";")
3535
3636-- | Compresses all whitespace.
3737--
3838compressWhitespace :: String -> String
39−compressWhitespace = replaceAll "[ \t\n][ \t\n]*" (const " ")
39+compressWhitespace = replaceAll "[ \t\n\r]+" (const " ")
4040
4141-- | Function that strips CSS comments away.
4242--
src/Hakyll/Web/Page/Read.hs+7−2
@@ -4,10 +4,10 @@ module Hakyll.Web.Page.Read
44 ( readPage
55 ) where
66
7−import Control.Applicative ((<$>), (<*>), (<*))
7+import Control.Applicative ((<$>), (<*>), (<*), (<|>))
88import qualified Data.Map as M
99
10−import Text.Parsec.Char (alphaNum, anyChar, char, newline, oneOf, string)
10+import Text.Parsec.Char (alphaNum, anyChar, char, oneOf, string)
1111import Text.Parsec.Combinator (choice, many1, manyTill, option, skipMany1)
1212import Text.Parsec.Prim (many, parse, skipMany, (<?>))
1313import Text.Parsec.String (Parser)
@@ -19,6 +19,11 @@ import Hakyll.Web.Page.Internal
1919inlineSpace :: Parser Char
2020inlineSpace = oneOf ['\t', ' '] <?> "space"
2121
22+-- | Parse Windows newlines as well (i.e. "\n" or "\r\n")
23+newline :: Parser String
24+newline = string "\n" -- Unix
25+ <|> string "\r\n" -- DOS
26+
2227-- | Parse a single metadata field
2328--
2429metadataField :: Parser (String, String)