Repository: rust-lang/mdBook (language: rust)

Issue:
Spacers in sidebar don't appear at correct level
For example, [the spacer in SUMMARY.md](https://github.com/rust-lang-nursery/mdBook/blob/master/book-example/src/SUMMARY.md#L25) is placed inside the subsection list, when it should be top-level:

![image](https://user-images.githubusercontent.com/853158/43154592-79612ed4-8f3a-11e8-86a1-bc66b67e97c6.png)



Discussion / hints:
Just noticed this. Still happening.
Copying my comment from #1730:

I suspect it would be around [here](https://github.com/rust-lang/mdBook/blob/0ec4b692f49b11d961e740e1ed14c4507d48621d/src/renderer/html_handlebars/helpers/toc.rs#L63-L67), where it uses an `<li>` for the spacer.  Perhaps it could use a different tag, like `<hr>`? However, this would need careful consideration of how it will change existing users, and whether or not it will affect their expected rendering.

It seems like the `<li>` spacer is rendered as a child of the previous section (which also causes it to disappear when folding is enabled), so I think `<hr>` would be bound by the `.section`'s `padding-left` either way.

Maybe, a workaround could be to delay [this call](https://github.com/rust-lang/mdBook/blob/1668ab78776ea966fa8ea4b335dd1394103d1cad/src/renderer/html_handlebars/helpers/toc.rs#L69) (and remove the `continue`, since it seems to also break the next sections) to when `current_level` is back to `1` (possibly [here](https://github.com/rust-lang/mdBook/blob/1668ab78776ea966fa8ea4b335dd1394103d1cad/src/renderer/html_handlebars/helpers/toc.rs#L99-L103), but it might bug when [this](https://github.com/rust-lang/mdBook/blob/1668ab78776ea966fa8ea4b335dd1394103d1cad/src/renderer/html_handlebars/helpers/toc.rs#L178-L182) runs).

This would force it to render inside `.chapter` and not inside `li > .section`, which would also fix its indentation.

Fix patch:
diff --git a/src/renderer/html_handlebars/helpers/toc.rs b/src/renderer/html_handlebars/helpers/toc.rs
index 81da5ef542..aabea028c0 100644
--- a/src/renderer/html_handlebars/helpers/toc.rs
+++ b/src/renderer/html_handlebars/helpers/toc.rs
@@ -74,12 +74,6 @@ impl HelperDef for RenderToc {
         let mut is_first_chapter = ctx.data().get("is_index").is_some();
 
         for item in chapters {
-            // Spacer
-            if item.contains_key("spacer") {
-                out.write("<li class=\"spacer\"></li>")?;
-                continue;
-            }
-
             let (section, level) = if let Some(s) = item.get("section") {
                 (s.as_str(), s.matches('.').count())
             } else {
@@ -118,6 +112,12 @@ impl HelperDef for RenderToc {
                 }
             }
 
+            // Spacer
+            if item.contains_key("spacer") {
+                out.write("<li class=\"spacer\"></li>")?;
+                continue;
+            }
+
             // Part title
             if let Some(title) = item.get("part") {
                 out.write("<li class=\"part-title\">")?;


Test patch: