mirror of
https://github.com/wassname/jupyter_contrib_nbextensions.git
synced 2026-06-27 16:10:24 +08:00
Merge pull request #1121 from jcb91/t2_0
[toc2] correct toc tree construction
This commit is contained in:
@@ -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 = [];
|
||||
@@ -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;
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user