Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The "Pretty" renderer generates incorrect output #111

Open
nad opened this issue Aug 30, 2017 · 1 comment
Open

The "Pretty" renderer generates incorrect output #111

nad opened this issue Aug 30, 2017 · 1 comment

Comments

@nad
Copy link

nad commented Aug 30, 2017

Consider the following code:

{-# LANGUAGE OverloadedStrings #-}

module Test where

import Text.Blaze.Html5 as H
import Text.Blaze.Html5.Attributes as A
import Text.Blaze.Html.Renderer.Pretty

example =
  putStr $ renderHtml $ docTypeHtml $ do
    H.head $ do
      meta ! charset "utf-8"
      H.title "Test"
    body $ pre $ do
      "Text"
      H.a $ "Text inside tag"
      "More text"

The resulting output:

<!DOCTYPE HTML>

<html>
    <head>
        <meta charset="utf-8">
        <title>
            Test
        </title>
    </head>
    <body>
        <pre>
            Text
            <a>
                Text inside tag
            </a>
            More text
        </pre>
    </body>
</html>

When the pre tag is used whitespace is significant, so I consider the output above to be incorrect. If the String renderer is used, then the output is better:

<!DOCTYPE HTML>
<html><head><meta charset="utf-8"><title>Test</title></head><body><pre>Text<a>Text inside tag</a>More text</pre></body></html>

The xhtml library handles this problem by inserting whitespace inside the tags (</a\n >). Perhaps you could do the same. (Or at least document that the pretty output is broken.)

@Profpatsch
Copy link

I stumbled over this as well. I guess it could be improved by having a list of tags where it shouldn’t create linebreaks.

I also noticed that when you have nested Append constructors, it will add linebreaks, leading to extra spaces in appended Content constructors (e.g. if you have Append (Content "foo") (Content "bar") it renders as foo bar instead of foobar.

This is especially crucial for https://hackage.haskell.org/package/ihp-hsx, which creates Appends for interpolated variables, so if I interpolate say let x = "x" in [hsx|foo ({x})|] the result will be "foo ( x )" instead of "foo (x)".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants