Skip to content

Commit da76ee0

Browse files
authored
Fix indent of tags without tag name when using renderFormatted() (#174)
#173 Off topic: Set execute flag on mvnw
1 parent 4a4c631 commit da76ee0

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

library/src/main/java/j2html/tags/ContainerTag.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ private void renderFormatted(int lvl, Appendable sb) throws IOException {
181181
if (this.isSelfFormattingTag()) {
182182
c.render(sb);
183183
} else {
184-
indent(sb, lvl-1);
185184
((ContainerTag<?>) c).renderFormatted(lvl-1, sb);
186185
}
187186
}
@@ -197,7 +196,7 @@ private void renderFormatted(int lvl, Appendable sb) throws IOException {
197196
lvl--;
198197
}
199198
}
200-
if (!this.isSelfFormattingTag()) {
199+
if (hasTagName() && !this.isSelfFormattingTag()) {
201200
indent(sb, lvl);
202201
}
203202
renderCloseTag(sb);

library/src/test/java/j2html/tags/RenderFormattedTest.java

+19
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,23 @@ public void testFormattedTags_each() throws Exception {
6767
));
6868
}
6969

70+
@Test
71+
public void testFormattedTags_nestedEach() throws Exception {
72+
assertThat(div(ul(each(asList(1, 2, 3), i -> li("Number " + i)))).renderFormatted(), is(
73+
"<div>\n" +
74+
" <ul>\n" +
75+
" <li>\n" +
76+
" Number 1\n" +
77+
" </li>\n" +
78+
" <li>\n" +
79+
" Number 2\n" +
80+
" </li>\n" +
81+
" <li>\n" +
82+
" Number 3\n" +
83+
" </li>\n" +
84+
" </ul>\n" +
85+
"</div>\n"
86+
));
87+
}
88+
7089
}

mvnw

100644100755
File mode changed.

0 commit comments

Comments
 (0)