From 9094b4ff264486daa7aa2e7a41434f76968a042b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Bercher?= Date: Sat, 22 Jul 2017 15:14:13 +0200 Subject: [PATCH 1/3] [toc2] use full URL for links, cf #1023 --- src/jupyter_contrib_nbextensions/nbextensions/toc2/toc2.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/jupyter_contrib_nbextensions/nbextensions/toc2/toc2.js b/src/jupyter_contrib_nbextensions/nbextensions/toc2/toc2.js index ef476b9ae..95f721b4d 100644 --- a/src/jupyter_contrib_nbextensions/nbextensions/toc2/toc2.js +++ b/src/jupyter_contrib_nbextensions/nbextensions/toc2/toc2.js @@ -23,7 +23,8 @@ function removeMathJaxPreview(elt) { var make_link = function(h, num_lbl) { var a = $(""); - a.attr("href", '#' + h.attr('id')); + a.attr("href", window.location.origin + window.location.pathname + '#' + h.attr('id')); + // a.attr("href", h.find('.anchor-link').attr('href')); // get the text *excluding* the link text, whatever it may be var hclone = h.clone(); hclone = removeMathJaxPreview(hclone); From e627dfccf33cffe2420fe232f3af025ac3fc12ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Bercher?= Date: Sat, 22 Jul 2017 15:16:18 +0200 Subject: [PATCH 2/3] [toc2] add a tag #skip to skip headers from being inserted in toc, cf #1027 --- src/jupyter_contrib_nbextensions/nbextensions/toc2/toc2.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/jupyter_contrib_nbextensions/nbextensions/toc2/toc2.js b/src/jupyter_contrib_nbextensions/nbextensions/toc2/toc2.js index 95f721b4d..1d5c670ad 100644 --- a/src/jupyter_contrib_nbextensions/nbextensions/toc2/toc2.js +++ b/src/jupyter_contrib_nbextensions/nbextensions/toc2/toc2.js @@ -550,6 +550,10 @@ var table_of_contents = function (cfg,st) { if (h.id=="Table-of-Contents"){ return; } //If h had already a number, remove it $(h).find(".toc-item-num").remove(); + // skip header if tag #skip is present + if (h.id.search('#skip') !== -1 ) { + $(h).text($(h).text().replace("#skip", "")); + return; } var num_str= incr_lbl(lbl_ary,level-1).join('.');// numbered heading labels var num_lbl= $("").addClass("toc-item-num") .text(num_str).append(' ').append(' '); From 27b3b4229652f43e8f5c80e5449dd3f52577eda9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Bercher?= Date: Sat, 22 Jul 2017 16:51:50 +0200 Subject: [PATCH 3/3] [toc2] use to skip headers from being inserted in toc, cf #1027 --- .../nbextensions/toc2/README.md | 7 ++++++- src/jupyter_contrib_nbextensions/nbextensions/toc2/toc2.js | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/jupyter_contrib_nbextensions/nbextensions/toc2/README.md b/src/jupyter_contrib_nbextensions/nbextensions/toc2/README.md index f65acf1a4..e3f24c9f7 100644 --- a/src/jupyter_contrib_nbextensions/nbextensions/toc2/README.md +++ b/src/jupyter_contrib_nbextensions/nbextensions/toc2/README.md @@ -10,7 +10,12 @@ The toc2 extension enables to collect all running headers and display them in a #### Second demo: ![](demo2.gif) -The table of contents is automatically updated when modifications occur in the notebook. The toc window can be moved and resized. It can be docked as a sidebar or dragged from the sidebar into a floating window. The table of contents can be collapsed or the window can be completely hidden. The navigation menu can be enabled/disabled via the nbextensions configuration utility. It can also be resized. The position, dimensions, and states (that is 'collapsed' and 'hidden' states) are remembered (actually stored in the notebook's metadata) and restored on the next session. The toc window also provides two links in its header for further functionalities: +The table of contents is automatically updated when modifications occur in the notebook. The toc window can be moved and resized. It can be docked as a sidebar or dragged from the sidebar into a floating window. The table of contents can be collapsed or the window can be completely hidden. The navigation menu can be enabled/disabled via the nbextensions configuration utility. It can also be resized. The position, dimensions, and states (that is 'collapsed' and 'hidden' states) are remembered (actually stored in the notebook's metadata) and restored on the next session. Headers can be skipped from being inserted in the toc by adding the html tag "" at the end of the header line; eg in +``` +## title " +``` + +The toc window also provides two links in its header for further functionalities: - the "n" link toggles automatic numerotation of all header lines - the "t" link toggles a toc cell in the notebook, which contains the actual table of contents, possibly with the numerotation of the different sections. diff --git a/src/jupyter_contrib_nbextensions/nbextensions/toc2/toc2.js b/src/jupyter_contrib_nbextensions/nbextensions/toc2/toc2.js index 1d5c670ad..e93e92d26 100644 --- a/src/jupyter_contrib_nbextensions/nbextensions/toc2/toc2.js +++ b/src/jupyter_contrib_nbextensions/nbextensions/toc2/toc2.js @@ -550,9 +550,9 @@ var table_of_contents = function (cfg,st) { if (h.id=="Table-of-Contents"){ return; } //If h had already a number, remove it $(h).find(".toc-item-num").remove(); - // skip header if tag #skip is present - if (h.id.search('#skip') !== -1 ) { - $(h).text($(h).text().replace("#skip", "")); + // skip header if an html tag with class 'tocSkip' is present + // eg in ## title + if ($(h).find('.tocSkip').length != 0 ) { return; } var num_str= incr_lbl(lbl_ary,level-1).join('.');// numbered heading labels var num_lbl= $("").addClass("toc-item-num")