Skip to content

The "Pretty" renderer generates incorrect output #111

@nad

Description

@nad

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.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions