Fix indent of tags without tag name when using renderFormatted() (#174)
https://github.com/tipsy/j2html/issues/173 Off topic: Set execute flag on mvnw
This commit is contained in:
@@ -181,7 +181,6 @@ public class ContainerTag<T extends ContainerTag<T>> extends Tag<T> {
|
||||
if (this.isSelfFormattingTag()) {
|
||||
c.render(sb);
|
||||
} else {
|
||||
indent(sb, lvl-1);
|
||||
((ContainerTag<?>) c).renderFormatted(lvl-1, sb);
|
||||
}
|
||||
}
|
||||
@@ -197,7 +196,7 @@ public class ContainerTag<T extends ContainerTag<T>> extends Tag<T> {
|
||||
lvl--;
|
||||
}
|
||||
}
|
||||
if (!this.isSelfFormattingTag()) {
|
||||
if (hasTagName() && !this.isSelfFormattingTag()) {
|
||||
indent(sb, lvl);
|
||||
}
|
||||
renderCloseTag(sb);
|
||||
|
||||
@@ -67,4 +67,23 @@ public class RenderFormattedTest {
|
||||
));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormattedTags_nestedEach() throws Exception {
|
||||
assertThat(div(ul(each(asList(1, 2, 3), i -> li("Number " + i)))).renderFormatted(), is(
|
||||
"<div>\n" +
|
||||
" <ul>\n" +
|
||||
" <li>\n" +
|
||||
" Number 1\n" +
|
||||
" </li>\n" +
|
||||
" <li>\n" +
|
||||
" Number 2\n" +
|
||||
" </li>\n" +
|
||||
" <li>\n" +
|
||||
" Number 3\n" +
|
||||
" </li>\n" +
|
||||
" </ul>\n" +
|
||||
"</div>\n"
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user