tipsy / j2html

Java to HTML generator. Enjoy typesafe HTML generation.
https://j2html.com/
Apache License 2.0
765 stars 136 forks source link

renderFormatted() causes unwanted whitespace to be rendered by browser #125

Closed dwalluck closed 5 years ago

dwalluck commented 6 years ago

The renderFormatted() method causes additional whitespace to be rendered by the browser. This applies to any tag that is a text container. It should probably be the case that tags with text content hug that content.

For example,

    <span>
        te
    </span>
    st
   <span>
       test
   </span>

would be rendered as

    <span>te</span>st
    <span>test</span>

having the opening and closing tags "hug" their content.

Otherwise, the browser will insert an additional spaces between one container tag and the other making it impossible to render them without space.

The HTML standard https://www.w3.org/TR/html401/appendix/notes.html#notes-line-breaks seems to indicate that the browser should render these two the same, but I tested with both in Google Chrome and Mozilla Firefox with the same results of an extra space.

This is complicated by the fact that if I try to use something like text("te"), text("st") it also adds newlines and indents even though this is just plain text in this case. Is there already a workaround to get these rendered right next to one another? Note that I cannot write text("test"). This was just an example. In reality, they are separate tags so they cannot be combined.

dwalluck commented 6 years ago

Sorry, as I said, the standard says that text within the container is rendered the same, so this "bug" relates to text that is between tags, not inside of them.

I still think it would be nice to have an option to render the the text within the tag without added whitespace. This already seems to be an option for tags where whitespace is important (like <pre>) so it shouldn't be too much of a change.

tipsy commented 6 years ago

@dwalluck If you create a PR for this I would be happy to merge it.