diff --git a/Hakyll/Web/Agda.hs b/Hakyll/Web/Agda.hs
--- a/Hakyll/Web/Agda.hs
+++ b/Hakyll/Web/Agda.hs
@@ -78,22 +78,21 @@
     begin contents =
         let (com, rest) = span (notCode beginCode) contents
         in Left ("\n\n" ++ concat [s | (_, s, _) <- com] ++ "\n\n") :
-           trimTop (end rest)
+           case rest of
+               []        -> []
+               _ : rest' -> end rest'
 
     end []  = []
-    end mis =
-        case span (notCode endCode) mis of
-            (a, e : b) -> Right (a ++ [trimEnd e]) : begin b
-            _          -> error "malformed file"
+    end mis = let (a, b) = span (notCode endCode) mis
+              in Right a :
+                 -- If there's nothing between \end{code} and \begin{code}, we
+                 -- start consuming code again.
+                 case b of
+                     []                                 -> error "malformed file"
+                     ((_, s, mi) : b') | beginCode s mi -> end b'
+                     (_          : b')                  -> begin b'
 
-    notCode :: (String -> MetaInfo -> Bool) -> (Integer, String, MetaInfo) -> Bool
     notCode f (_, s, mi) = not (f s mi)
-
-    trimTop (Right ((pos, s, mi) : rs) : rest) =
-        Right ((pos, dropWhile isSpace s, mi) : rs) : rest
-    trimTop x = x
-
-    trimEnd (pos, s, mi) = (pos, reverse (dropWhile isSpace (reverse s)), mi)
 
 annotate :: TopLevelModuleName -> Integer -> MetaInfo -> Html -> Html
 annotate m pos mi = anchor ! attributes
diff --git a/css/agda.css b/css/agda.css
--- a/css/agda.css
+++ b/css/agda.css
@@ -1,3 +1,8 @@
+/* Adapted from `src/data/Agda.css' from the Agda package, see
+   <http://code.haskell.org/Agda/LICENSE> for the license and the copyright
+   information.
+*/
+
 /* Aspects. */
 pre.Agda a.Comment       { color: #B22222 }
 pre.Agda a.Keyword       { color: #CD6600 }
diff --git a/hakyll-agda.cabal b/hakyll-agda.cabal
--- a/hakyll-agda.cabal
+++ b/hakyll-agda.cabal
@@ -1,6 +1,6 @@
 Cabal-version:      >= 1.6
 Name:               hakyll-agda
-Version:            0.1
+Version:            0.1.1
 Author:             Francesco Mazzoli (f@mazzo.li)
 Maintainer:         Francesco Mazzoli (f@mazzo.li)
 Build-Type:         Simple
@@ -21,7 +21,7 @@
 
 Library
     Build-Depends:    base >= 3 && < 5,
-                      hakyll >= 4.2 && < 5,
+                      hakyll >= 4.2.2 && < 5,
                       Agda >= 2.3 && < 3,
                       pandoc >= 1.10 && < 2,
                       xhtml >= 3000.2 && < 3000.3,
