Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions src/jupyter_contrib_nbextensions/nbextensions/toc2/toc2.js
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,6 @@

var cell_toc_text = " # Table of Contents\n";
var depth = 1;
var li = ul; //yes, initialize li with ul!
all_headers = $("#notebook").find(":header"); // update all_headers
var min_lvl = 1 + Number(Boolean(cfg.skip_h1_title)),
lbl_ary = [];
Expand Down Expand Up @@ -644,18 +643,16 @@
}

// walk down levels
for (var elm = li; depth < level; depth++) {
var new_ul = $("<ul/>").addClass("toc-item");
elm.append(new_ul);
elm = ul = new_ul;
for (; depth < level; depth++) {
var li = ul.children('li:last-child');
if (li.length < 1) {
li = $('<li>').appendTo(ul);
}
ul = $('<ul class="toc-item">').appendTo(li);
}
// walk up levels
for (; depth > level; depth--) {
// up twice: the enclosing <ol> and <li> it was inserted in
ul = ul.parent();
while (!ul.is('ul')) {
ul = ul.parent();
}
ul = ul.parent().closest('.toc-item');
}

var toc_mod_id = h.attr('id') + '-' + num_str;
Expand All @@ -665,8 +662,10 @@
$('<a>').addClass('toc-mod-link').attr('id', toc_mod_id).prependTo(h);

// Create toc entry, append <li> tag to the current <ol>.
li = $('<li>').append($('<span/>').append(make_link(h, toc_mod_id)));
ul.append(li);
ul.append(
$('<li>').append(
$('<span>').append(
make_link(h, toc_mod_id))));
});

// update navigation menu
Expand Down