Search code examples
haskellyesodhamlet

How to avoid whitespace after a tag (link) in Hamlet templates?


I cannot find a way to render a link and then comma or full stop right after it, without whitespace between the link and punctuation. Here is my initial attempt:

<p>
  You can find more information #
  <a href="@{SomeRouteR}">here
  \.

or

<p>
  You can find more information #
  <a href="@{SomeRouteR}">here
  .

This inserts space between the word “here” and “.”.

Another option is:

<p>
  You can find more information #
  <a href="@{SomeRouteR}">here</a>.

This looks like a win, but HTML is malformed:

<p>You can find more information <a href="…">here</a>.</a></p>

Is there a way to avoid whitespace between the link and punctuation/other element?


Solution

  • Some options:

    1. Add $newline never to the top of your file, to change the default of adding newlines after tags.
    2. Add a # immediately following the word here to disable the automatic newline for just that tag.
    3. Use the explicit end tag like you tried to. But to make this work, you need to start the line with a backslash to tell Hamlet not to autoclose the tag for you: \<a href=#>here</a>.