summaryrefslogtreecommitdiff
path: root/src/Hakyll/Web/Template
diff options
context:
space:
mode:
authorsamgd <sam@samgd.com>2016-07-25 12:47:30 +0200
committersamgd <sam@samgd.com>2016-07-25 12:47:30 +0200
commit82d6402ba38b9e1ea789e83c5ea7d08bcbeff467 (patch)
treeb0565d90ca1b681d6834adbde66e52ad133152cd /src/Hakyll/Web/Template
parent43c969f326082d29d8e340ee865414deb87b8ac5 (diff)
downloadhakyll-82d6402ba38b9e1ea789e83c5ea7d08bcbeff467.tar.gz
Trim instructions. TrimRd chunk might need TrimL. Trim tests.
Diffstat (limited to 'src/Hakyll/Web/Template')
-rw-r--r--src/Hakyll/Web/Template/Trim.hs20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/Hakyll/Web/Template/Trim.hs b/src/Hakyll/Web/Template/Trim.hs
index 4ea3438..bc7e691 100644
--- a/src/Hakyll/Web/Template/Trim.hs
+++ b/src/Hakyll/Web/Template/Trim.hs
@@ -1,5 +1,5 @@
--------------------------------------------------------------------------------
--- | Module for trimming whitespace.
+-- | Module for trimming whitespace
module Hakyll.Web.Template.Trim
( trim
) where
@@ -20,15 +20,22 @@ trim = cleanse . canonicalize
--------------------------------------------------------------------------------
+-- | Apply the Trim nodes to the Chunks.
cleanse :: [TemplateElement] -> [TemplateElement]
cleanse = recurse cleanse . process
where process [] = []
- process (TrimR:Chunk str:ts) = Chunk (lstrip str):process ts
- process (Chunk str:TrimL:ts) = Chunk (rstrip str):process ts
- process (t:ts) = t:process ts
+ process (TrimR:Chunk str:ts) = let str' = dropWhile isSpace str
+ in if null str'
+ then process ts
+ -- Might need to TrimL.
+ else process $ Chunk str':ts
+
+ process (Chunk str:TrimL:ts) = let str' = dropWhileEnd isSpace str
+ in if null str'
+ then process ts
+ else Chunk str':process ts
- lstrip = dropWhile isSpace
- rstrip = dropWhileEnd isSpace
+ process (t:ts) = t:process ts
--------------------------------------------------------------------------------
-- | Enforce the invariant that:
@@ -75,6 +82,7 @@ dedupe = recurse dedupe . process
--------------------------------------------------------------------------------
+-- | @'recurse' f t@ applies f to every '[TemplateElement]' in t.
recurse :: ([TemplateElement] -> [TemplateElement])
-> [TemplateElement]
-> [TemplateElement]