Search code examples
haskellhtml-templatesblaze-htmlihp

Commenting hsx blaze-html lines in Haskell


I'm starting to experiment with IHP's webframework. I am testing some different page layouts and I can't seem to find the right way of commenting out html within the hsx QuasiQuote (which has the blaze-html syntax) whilst experimenting with the design. For example, I want to temporarily comment the link to Users in the following:

 [hsx |
 <a class="nav-link active" href={UsersAction}> Users  </a>
 <a class="nav-link active" href={SitesAction}> Current Projects </a>
 <a class="nav-link active" href={NewSiteAction}> Add New Project </a>
 |]

I have tried commenting the line html style:

[hsx |
  <!-- <a class="nav-link active" href={UsersAction}> Users  </a> -->
|]

but that yields a compilation error:

unexpected '!'

I have also tried escaping it in curly braces as a haskell comment but that yields

compileToHaskell(-- <a class="nav-link active" href={UsersAction}> Users  </a>   ): "0\nSrcLoc \"\" 1 65\nParse error: EOF\n"

Essentially I am looking for a way to comment lines or blocks of code within an [hsx|...|] QuasiQuote block but I am unsure of what exactly I need to escape.


Solution

  • HSX previously had no support for HTML comments. I've just added this to the HSX syntax: https://github.com/digitallyinduced/ihp/pull/349

    Will be part of the next version of IHP released later today. Then this syntax will work:

    [hsx|
    <div>
        <!-- Comment -->
    </div>
    |]