diff --git a/HSX/JMacro.hs b/HSX/JMacro.hs
--- a/HSX/JMacro.hs
+++ b/HSX/JMacro.hs
@@ -51,8 +51,15 @@
       do i <- lift nextInteger
          asChild $ genElement (Nothing, "script")
                     [asAttr ("type" := "text/javascript")]
-                    [asChild (render $ jsToDoc $ jsSaturate (Just ('i' : show i)) jstat)]
-
+                    [asChild (escapeForHtml $ render $ jsToDoc $ jsSaturate (Just ('i' : show i)) jstat)]
+      where
+        escapeForHtml :: String -> String
+        escapeForHtml [] = []
+        escapeForHtml [c] = [c]
+        escapeForHtml (b:c:cs)
+            | b == '<' && c == '/' 
+                        = b : '\\' : c : (escapeForHtml cs)
+            | otherwise = b : escapeForHtml (c : cs)
 
 instance (IntegerSupply m, IsName n, EmbedAsAttr m (Attr Name String)) => EmbedAsAttr m (Attr n JStat) where
   asAttr (n := jstat) = 
diff --git a/hsx-jmacro.cabal b/hsx-jmacro.cabal
--- a/hsx-jmacro.cabal
+++ b/hsx-jmacro.cabal
@@ -1,5 +1,5 @@
 Name:                hsx-jmacro
-Version:             6.0.0
+Version:             6.0.1
 Synopsis:            hsx+jmacro support
 Description:         HSX allows for the use of literal XML in Haskell program text. JMacro allows for the use of javascript-syntax for generating javascript in Haskell. This library makes it easy to embed JMacro generated javascript in HSX templates.
 Homepage:            http://www.happstack.com/
