haskellhaskell-snap-frameworkheist

HTML doctype rendered with Snap / Heist template


I'm having issues with https://hackage.haskell.org/package/snap-1.0.0.1/docs/Snap-Snaplet-Heist-Interpreted.html#v:render when trying to render a template. The issue only occurs if I have the following as the contents of the template:

<!DOCTYPE html>
</html>

while the following content renders fine

<html>
</html>

So it seems to be something to do with the HTML doctype.

The exception that occurs:

*** Exception: 
Initializer threw an exception...
/home/chris/Projects/Haskell/pkgscrape/Snap/snaplets/heist/templates/compareForm.tpl "/home/chris/Projects/Haskell/pkgscrape/Snap/snaplets/heist/templates/compareForm.tpl" (line 21, column 2):
unexpected "/"
CallStack (from HasCallStack):
  error, called at src/Snap/Snaplet/Heist/Internal.hs:74:35 in snap-1.0.0.1-6iNEjVc81Z8CCk3FAMxZ8z:Snap.Snaplet.Heist.Internal

...but before it died it generated the following output:
Initializing myapp @ /
Initializing heist @ /heist


CallStack (from HasCallStack):
  error, called at src/Snap/Snaplet/Internal/Initializer.hs:597:13 in snap-1.0.0.1-6iNEjVc81Z8CCk3FAMxZ8z:Snap.Snaplet.Internal.Initializer

Solution

  • Your first example isn't valid HTML. I think you want:

    <!DOCTYPE html>
    <html>
    </html>
    

    The doctype is not the same as an opening <html> tag.

    Browsers are really permissive, so they'll accept your version without complaint, but Interpreted Heist tries to parse templates into valid HTML, so it chokes on an ending tag (</html>) without the correct opening tag first.