diff --git a/Language/Haskell/HsColour.hs b/Language/Haskell/HsColour.hs
--- a/Language/Haskell/HsColour.hs
+++ b/Language/Haskell/HsColour.hs
@@ -40,28 +40,31 @@
          -> String      -- ^ Coloured Haskell source code.
 hscolour output pref anchor partial title False =
         (if partial then id else top'n'tail output title) .
-        hscolour' output pref anchor
+        hscolour' output pref anchor 1
 hscolour output pref anchor partial title True  =
         (if partial then id else top'n'tail output title) .
-        concatMap chunk . joinL . classify . inlines
+        concat . chunk 1 . joinL . classify . inlines
   where
-    chunk (Code c) = hscolour' output pref anchor c
-    chunk (Lit c)  = c
+    chunk _        []     = []
+    chunk n (Code c: cs)  = hscolour' output pref anchor n c
+                              : chunk (n + length (lines c)) cs
+    chunk n (Lit c:  cs)  = c : chunk n cs
 
 -- | The actual colourising worker, despatched on the chosen output format.
 hscolour' :: Output      -- ^ Output format.
           -> ColourPrefs -- ^ Colour preferences (for formats that support them)
           -> Bool        -- ^ Whether to include anchors.
+          -> Int         -- ^ Starting line number (for line anchors)
           -> String      -- ^ Haskell source code.
           -> String      -- ^ Coloured Haskell source code.
-hscolour' TTY       pref _      = TTY.hscolour     pref
-hscolour' (TTYg tt) pref _      = TTY.hscolourG tt pref
-hscolour' MIRC      pref _      = MIRC.hscolour    pref
-hscolour' LaTeX     pref _      = LaTeX.hscolour   pref
-hscolour' HTML      pref anchor = HTML.hscolour    pref anchor
-hscolour' CSS       _    anchor = CSS.hscolour          anchor
-hscolour' ICSS      pref anchor = ICSS.hscolour    pref anchor
-hscolour' ACSS      _    anchor = ACSS.hscolour         anchor
+hscolour' TTY       pref _      _ = TTY.hscolour     pref
+hscolour' (TTYg tt) pref _      _ = TTY.hscolourG tt pref
+hscolour' MIRC      pref _      _ = MIRC.hscolour    pref
+hscolour' LaTeX     pref _      _ = LaTeX.hscolour   pref
+hscolour' HTML      pref anchor n = HTML.hscolour    pref anchor n
+hscolour' CSS       _    anchor n = CSS.hscolour          anchor n
+hscolour' ICSS      pref anchor n = ICSS.hscolour    pref anchor n
+hscolour' ACSS      _    anchor n = ACSS.hscolour         anchor n
 
 -- | Choose the right headers\/footers, depending on the output format.
 top'n'tail :: Output           -- ^ Output format
@@ -96,14 +99,21 @@
 classify ::  [String] -> [Lit]
 classify []             = []
 classify (x:xs) | "\\begin{code}"`isPrefixOf`x
-                        = Lit x: allProg xs
-   where allProg []     = []  -- Should give an error message,
-                              -- but I have no good position information.
-         allProg (x:xs) | "\\end{code}"`isPrefixOf`x
-                        = Lit x: classify xs
-         allProg (x:xs) = Code x: allProg xs
+                        = Lit x: allProg "code" xs
+classify (x:xs) | "\\begin{spec}"`isPrefixOf`x
+                        = Lit x: allProg "spec" xs
 classify (('>':x):xs)   = Code ('>':x) : classify xs
 classify (x:xs)         = Lit x: classify xs
+
+
+allProg name  = go 
+  where
+    end       = "\\end{" ++ name ++ "}"
+    go []     = []  -- Should give an error message,
+                    -- but I have no good position information.
+    go (x:xs) | end `isPrefixOf `x
+              = Lit x: classify xs
+    go (x:xs) = Code x: go xs
 
 -- | Join up chunks of code\/comment that are next to each other.
 joinL :: [Lit] -> [Lit]
diff --git a/Language/Haskell/HsColour/ACSS.hs b/Language/Haskell/HsColour/ACSS.hs
--- a/Language/Haskell/HsColour/ACSS.hs
+++ b/Language/Haskell/HsColour/ACSS.hs
@@ -26,19 +26,21 @@
 
 -- | Formats Haskell source code using HTML and mouse-over annotations 
 hscolour :: Bool     -- ^ Whether to include anchors.
+         -> Int      -- ^ Starting line number (for line anchors).
          -> String   -- ^ Haskell source code, Annotations as comments at end
          -> String   -- ^ Coloured Haskell source code.
 
-hscolour anchor = hsannot anchor . splitSrcAndAnns
+hscolour anchor n = hsannot anchor n . splitSrcAndAnns
 
 -- | Formats Haskell source code using HTML and mouse-over annotations 
 hsannot  :: Bool             -- ^ Whether to include anchors.
+         -> Int              -- ^ Starting line number (for line anchors).
          -> (String, AnnMap) -- ^ Haskell Source, Annotations
          -> String           -- ^ Coloured Haskell source code.
 
-hsannot anchor = 
+hsannot anchor n = 
     CSS.pre
-    . (if anchor then -- renderNewLinesAnchors .
+    . (if anchor then -- renderNewLinesAnchors n .
                       concatMap (renderAnchors renderAnnotToken)
                       . insertAnnotAnchors
                  else concatMap renderAnnotToken)
diff --git a/Language/Haskell/HsColour/CSS.hs b/Language/Haskell/HsColour/CSS.hs
--- a/Language/Haskell/HsColour/CSS.hs
+++ b/Language/Haskell/HsColour/CSS.hs
@@ -13,13 +13,14 @@
 
 -- | Formats Haskell source code as a complete HTML document with CSS.
 hscolour :: Bool   -- ^ Whether to include anchors.
+         -> Int    -- ^ Starting line number (for line anchors).
          -> String -- ^ Haskell source code.
          -> String -- ^ An HTML document containing the coloured 
                    --   Haskell source code.
-hscolour anchor =
+hscolour anchor n =
   pre
   . (if anchor 
-        then renderNewLinesAnchors
+        then renderNewLinesAnchors n
              . concatMap (renderAnchors renderToken)
              . insertAnchors
         else concatMap renderToken)
diff --git a/Language/Haskell/HsColour/HTML.hs b/Language/Haskell/HsColour/HTML.hs
--- a/Language/Haskell/HsColour/HTML.hs
+++ b/Language/Haskell/HsColour/HTML.hs
@@ -17,11 +17,12 @@
 -- | Formats Haskell source code using HTML with font tags.
 hscolour :: ColourPrefs -- ^ Colour preferences.
          -> Bool        -- ^ Whether to include anchors.
+         -> Int         -- ^ Starting line number (for line anchors).
          -> String      -- ^ Haskell source code.
          -> String      -- ^ Coloured Haskell source code.
-hscolour pref anchor = 
+hscolour pref anchor n = 
     pre
-    . (if anchor then renderNewLinesAnchors
+    . (if anchor then renderNewLinesAnchors n
                       . concatMap (renderAnchors (renderToken pref))
                       . insertAnchors
                  else concatMap (renderToken pref))
@@ -55,8 +56,8 @@
 renderComment (x:xs) = escape [x] ++ renderComment xs
 renderComment [] = []
 
-renderNewLinesAnchors :: String -> String
-renderNewLinesAnchors = unlines . map render . zip [1..] . lines
+renderNewLinesAnchors :: Int -> String -> String
+renderNewLinesAnchors n = unlines . map render . zip [n..] . lines
     where render (line, s) = "<a name=\"line-" ++ show line ++ "\"></a>" ++ s
 
 -- Html stuff
diff --git a/Language/Haskell/HsColour/InlineCSS.hs b/Language/Haskell/HsColour/InlineCSS.hs
--- a/Language/Haskell/HsColour/InlineCSS.hs
+++ b/Language/Haskell/HsColour/InlineCSS.hs
@@ -11,13 +11,14 @@
 -- | Formats Haskell source code as a complete HTML document with inline styling
 hscolour :: ColourPrefs	-- ^ Preferences for styling.
          -> Bool   -- ^ Whether to include anchors.
+         -> Int    -- ^ Starting line number (for line anchors).
          -> String -- ^ Haskell source code.
          -> String -- ^ An HTML document containing the coloured 
                    --   Haskell source code.
-hscolour prefs anchor =
+hscolour prefs anchor n =
   pre
   . (if anchor 
-        then renderNewLinesAnchors
+        then renderNewLinesAnchors n
              . concatMap (renderAnchors (renderToken prefs))
              . insertAnchors
         else concatMap (renderToken prefs))
diff --git a/hscolour.cabal b/hscolour.cabal
--- a/hscolour.cabal
+++ b/hscolour.cabal
@@ -1,6 +1,6 @@
 Name: hscolour
-Version: 1.20.3
-Copyright: 2003-2012 Malcolm Wallace; 2006 Bjorn Bringert
+Version: 1.21
+Copyright: 2003-2015 Malcolm Wallace; 2006 Bjorn Bringert
 Maintainer: Malcolm Wallace
 Author: Malcolm Wallace
 Homepage: http://code.haskell.org/~malcolm/hscolour/
@@ -51,7 +51,7 @@
   Main-is: HsColour.hs
   --ghc-options: -O -W
   Extensions: CPP
-  cpp-options: -DMAJOR=1 -DMINOR=20
+  cpp-options: -DMAJOR=1 -DMINOR=21
 
 
 
