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:
Oliver Becker
2021-04-24 21:52:50 +02:00
committed by GitHub
parent 4a4c6314d8
commit da76ee0d2b
3 changed files with 20 additions and 2 deletions

View File

@@ -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);

View File

@@ -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"
));
}
}

0
mvnw vendored Normal file → Executable file
View File