Skip to content

Commit

Permalink
Merge pull request #1030 from jfbercher/toc2
Browse files Browse the repository at this point in the history
toc2 -- Full url in links | #skip tag to skip headers from being inserted
  • Loading branch information
jcb91 authored Jul 28, 2017
2 parents 91d4244 + 27b3b42 commit 33546ef
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/jupyter_contrib_nbextensions/nbextensions/toc2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<a class='tocSkip'>" at the end of the header line; eg in
```
## title <a class='tocSkip'>"
```

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.
Expand Down
7 changes: 6 additions & 1 deletion src/jupyter_contrib_nbextensions/nbextensions/toc2/toc2.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ function removeMathJaxPreview(elt) {

var make_link = function(h, num_lbl) {
var a = $("<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);
Expand Down Expand Up @@ -549,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 an html tag with class 'tocSkip' is present
// eg in ## title <a class='tocSkip'>
if ($(h).find('.tocSkip').length != 0 ) {
return; }
var num_str= incr_lbl(lbl_ary,level-1).join('.');// numbered heading labels
var num_lbl= $("<span/>").addClass("toc-item-num")
.text(num_str).append('&nbsp;').append('&nbsp;');
Expand Down

0 comments on commit 33546ef

Please sign in to comment.