How to make j2html format 'each' tags correctly

532 Views Asked by At

I'm having trouble getting j2html to format all of its generated output. Elements generated by most of the tags work as expected, but the 'each' tag doesn't format.

Consider the following Java method:

private void temp() {
    List<String> middle = Arrays.asList("One", "Two", "Three");

    String html =
      html(
        body(
          p("Before"),
          ul(
            each(middle, item ->
              li(
                span(item)
              )
            )
          ),
          p("After")
        )
      ).renderFormatted();

    System.out.println(html);
}

the generated HTML is:

<html>
    <body>
        <p>
            Before
        </p>
        <ul>
            <li><span>One</span></li><li><span>Two</span></li><li><span>Three</span></li>
        </ul>
        <p>
            After
        </p>
    </body>
</html>

As we can see, the content of the 'each' block is printed as a single unformatted line. How do we fix this?

1

There are 1 best solutions below

1
On BEST ANSWER

I have also encountered this bug, wherever you use each the text is all rendered in one line, I had already raised a bug here

https://github.com/tipsy/j2html/issues/97