Skip to content

Commit

Permalink
Merge pull request #152 from quornian/master
Browse files Browse the repository at this point in the history
Make sure <ul><li> and </li></ul> are balanced
  • Loading branch information
azerupi authored Jul 23, 2016
2 parents a4a277c + b0e5f37 commit b6df992
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/renderer/html_handlebars/helpers/toc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()));
Expand Down

0 comments on commit b6df992

Please sign in to comment.