Make sure <ul><li> and </li></ul> are balanced

This commit is contained in:
Ian Thompson 2016-07-16 10:23:22 -04:00
parent a4a277cb50
commit b0e5f375ba
1 changed files with 11 additions and 4 deletions

View File

@ -39,14 +39,17 @@ impl HelperDef for RenderToc {
};
if level > current_level {
try!(rc.writer.write("<li>".as_bytes()));
try!(rc.writer.write("<ul class=\"section\">".as_bytes()));
while level > current_level {
try!(rc.writer.write("<li>".as_bytes()));
try!(rc.writer.write("<ul class=\"section\">".as_bytes()));
current_level += 1;
}
try!(rc.writer.write("<li>".as_bytes()));
} else if level < current_level {
while level < current_level {
try!(rc.writer.write("</ul>".as_bytes()));
try!(rc.writer.write("</li>".as_bytes()));
current_level = current_level - 1;
current_level -= 1;
}
try!(rc.writer.write("<li>".as_bytes()));
} else {
@ -122,7 +125,11 @@ impl HelperDef for RenderToc {
try!(rc.writer.write("</li>".as_bytes()));
current_level = level;
}
while current_level > 1 {
try!(rc.writer.write("</ul>".as_bytes()));
try!(rc.writer.write("</li>".as_bytes()));
current_level -= 1;
}
try!(rc.writer.write("</ul>".as_bytes()));