Skip to content

Commit

Permalink
Merge pull request #1121 from jcb91/t2_0
Browse files Browse the repository at this point in the history
[toc2] correct toc tree construction
  • Loading branch information
jcb91 authored Oct 12, 2017
2 parents 08ab4cb + abfc773 commit 59b98a4
Showing 1 changed file with 11 additions and 12 deletions.
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 @@ -618,7 +618,6 @@
$("#toc").empty().append(ul);

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 @@ -663,18 +662,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 @@ -684,8 +681,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

0 comments on commit 59b98a4

Please # to comment.