on master help sign in
Proper string trimming.
d3ce014Jasper Van der Jeugt
src/Text/Hakyll/Page.hs+3−3
@@ -18,6 +18,7 @@ import Data.Maybe
18import System.FilePath
18import System.FilePath
19import System.IO
19import System.IO
20
20
21+import Text.Hakyll.Util
21import Text.Pandoc
22import Text.Pandoc
22
23
23-- | A Page is basically key-value mapping. Certain keys have special
24-- | A Page is basically key-value mapping. Certain keys have special
@@ -27,7 +28,6 @@ type Page = M.Map String PageValue
27-- | We use a ByteString for obvious reasons.
28-- | We use a ByteString for obvious reasons.
28type PageValue = B.ByteString
29type PageValue = B.ByteString
29
30
30−
31-- | Add a key-value mapping to the Page.
31-- | Add a key-value mapping to the Page.
32addContext :: String -> String -> Page -> Page
32addContext :: String -> String -> Page -> Page
33addContext key value = M.insert key (B.pack value)
33addContext key value = M.insert key (B.pack value)
@@ -61,8 +61,8 @@ readMetaData handle = do
61 line <- hGetLine handle
61 line <- hGetLine handle
62 if isDelimiter line then return []
62 if isDelimiter line then return []
63 else do others <- readMetaData handle
63 else do others <- readMetaData handle
64− return $ (trim . break (== ':')) line : others
64+ return $ (trimPair . break (== ':')) line : others
65− where trim (key, value) = (key, dropWhile (`elem` ": ") value)
65+ where trimPair (key, value) = (trim key, trim $ tail value)
66
66
67isDelimiter :: String -> Bool
67isDelimiter :: String -> Bool
68isDelimiter = L.isPrefixOf "---"
68isDelimiter = L.isPrefixOf "---"
src/Text/Hakyll/Util.hs+8−1
@@ -1,11 +1,13 @@
1module Text.Hakyll.Util
1module Text.Hakyll.Util
2 ( makeDirectories,
2 ( makeDirectories,
3− getRecursiveContents
3+ getRecursiveContents,
4+ trim
4 ) where
5 ) where
5
6
6import System.Directory
7import System.Directory
7import System.FilePath
8import System.FilePath
8import Control.Monad
9import Control.Monad
10+import Data.Char
9
11
10-- | Given a path to a file, try to make the path writable by making
12-- | Given a path to a file, try to make the path writable by making
11-- all directories on the path.
13-- all directories on the path.
@@ -27,3 +29,8 @@ getRecursiveContents topdir = do
27 else return [path]
29 else return [path]
28 return (concat paths)
30 return (concat paths)
29 where isProper = not . (== '.') . head
31 where isProper = not . (== '.') . head
32+
33+-- | Trim a string (drop spaces and tabs at both sides).
34+trim :: String -> String
35+trim = reverse . trim' . reverse . trim'
36+ where trim' = dropWhile isSpace