diff --git a/src/renderer/html_handlebars/helpers/toc.rs b/src/renderer/html_handlebars/helpers/toc.rs
index 1246f9d3..9d924086 100644
--- a/src/renderer/html_handlebars/helpers/toc.rs
+++ b/src/renderer/html_handlebars/helpers/toc.rs
@@ -35,7 +35,11 @@ impl HelperDef for RenderToc {
try!(rc.writer.write("
".as_bytes()));
try!(rc.writer.write("- ".as_bytes()));
} else if level < current_level {
- try!(rc.writer.write("
".as_bytes()));
+ while level < current_level {
+ try!(rc.writer.write("".as_bytes()));
+ try!(rc.writer.write("".as_bytes()));
+ current_level = current_level - 1;
+ }
try!(rc.writer.write("".as_bytes()));
}
else {