diff --git a/Text/Hamlet/Parse.hs b/Text/Hamlet/Parse.hs
--- a/Text/Hamlet/Parse.hs
+++ b/Text/Hamlet/Parse.hs
@@ -70,7 +70,7 @@
 parseLines set = mapM (go . killCarriage) . lines where
     go s = do
         let (spaces, s') = countSpaces 0 s
-        l <- parseLine set s'
+        l <- parseLine set $ killTrailingDollar s'
         Ok (spaces, l)
     countSpaces i (' ':rest) = countSpaces (i + 1) rest
     countSpaces i ('\t':rest) = countSpaces (i + 4) rest
@@ -79,6 +79,10 @@
         | null s = s
         | last s == '\r' = init s
         | otherwise = s
+    killTrailingDollar "" = ""
+    killTrailingDollar x
+        | last x == '$' && odd (length $ filter (== '$') x) = init x
+        | otherwise = x
 
 parseLine :: HamletSettings -> String -> Result Line
 parseLine set "!!!" =
diff --git a/hamlet.cabal b/hamlet.cabal
--- a/hamlet.cabal
+++ b/hamlet.cabal
@@ -1,5 +1,5 @@
 name:            hamlet
-version:         0.3.0
+version:         0.3.1
 license:         BSD3
 license-file:    LICENSE
 author:          Michael Snoyman <michael@snoyman.com>
diff --git a/runtests.hs b/runtests.hs
--- a/runtests.hs
+++ b/runtests.hs
@@ -49,6 +49,7 @@
     , testCase "attribute conditionals" caseAttribCond
     , testCase "non-ascii" caseNonAscii
     , testCase "maybe function" caseMaybeFunction
+    , testCase "trailing dollar sign" caseTrailingDollarSign
     ]
 
 data Url = Home | Sub SubUrl
@@ -283,3 +284,9 @@
 $maybe Just.urlParams x
     @?x.theArg@
 |]
+
+caseTrailingDollarSign :: Assertion
+caseTrailingDollarSign =
+    helper "trailing space \ndollar sign $" [$hamlet|trailing space $
+\
+dollar sign $$|]
