Skip to content

Commit b0e5f37

Browse files
committed
Make sure <ul><li> and </li></ul> are balanced
1 parent a4a277c commit b0e5f37

File tree

1 file changed

+11
-4
lines changed
  • src/renderer/html_handlebars/helpers

1 file changed

+11
-4
lines changed

src/renderer/html_handlebars/helpers/toc.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,17 @@ impl HelperDef for RenderToc {
3939
};
4040

4141
if level > current_level {
42-
try!(rc.writer.write("<li>".as_bytes()));
43-
try!(rc.writer.write("<ul class=\"section\">".as_bytes()));
42+
while level > current_level {
43+
try!(rc.writer.write("<li>".as_bytes()));
44+
try!(rc.writer.write("<ul class=\"section\">".as_bytes()));
45+
current_level += 1;
46+
}
4447
try!(rc.writer.write("<li>".as_bytes()));
4548
} else if level < current_level {
4649
while level < current_level {
4750
try!(rc.writer.write("</ul>".as_bytes()));
4851
try!(rc.writer.write("</li>".as_bytes()));
49-
current_level = current_level - 1;
52+
current_level -= 1;
5053
}
5154
try!(rc.writer.write("<li>".as_bytes()));
5255
} else {
@@ -122,7 +125,11 @@ impl HelperDef for RenderToc {
122125

123126
try!(rc.writer.write("</li>".as_bytes()));
124127

125-
current_level = level;
128+
}
129+
while current_level > 1 {
130+
try!(rc.writer.write("</ul>".as_bytes()));
131+
try!(rc.writer.write("</li>".as_bytes()));
132+
current_level -= 1;
126133
}
127134

128135
try!(rc.writer.write("</ul>".as_bytes()));

0 commit comments

Comments
 (0)