Skip to content

Commit 33546ef

Browse files
authored
Merge pull request #1030 from jfbercher/toc2
toc2 -- Full url in links | #skip tag to skip headers from being inserted
2 parents 91d4244 + 27b3b42 commit 33546ef

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/jupyter_contrib_nbextensions/nbextensions/toc2/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ The toc2 extension enables to collect all running headers and display them in a
1010
#### Second demo:
1111
![](demo2.gif)
1212

13-
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:
13+
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
14+
```
15+
## title <a class='tocSkip'>"
16+
```
17+
18+
The toc window also provides two links in its header for further functionalities:
1419

1520
- the "n" link toggles automatic numerotation of all header lines
1621
- 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.

src/jupyter_contrib_nbextensions/nbextensions/toc2/toc2.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ function removeMathJaxPreview(elt) {
2323

2424
var make_link = function(h, num_lbl) {
2525
var a = $("<a/>");
26-
a.attr("href", '#' + h.attr('id'));
26+
a.attr("href", window.location.origin + window.location.pathname + '#' + h.attr('id'));
27+
// a.attr("href", h.find('.anchor-link').attr('href'));
2728
// get the text *excluding* the link text, whatever it may be
2829
var hclone = h.clone();
2930
hclone = removeMathJaxPreview(hclone);
@@ -549,6 +550,10 @@ var table_of_contents = function (cfg,st) {
549550
if (h.id=="Table-of-Contents"){ return; }
550551
//If h had already a number, remove it
551552
$(h).find(".toc-item-num").remove();
553+
// skip header if an html tag with class 'tocSkip' is present
554+
// eg in ## title <a class='tocSkip'>
555+
if ($(h).find('.tocSkip').length != 0 ) {
556+
return; }
552557
var num_str= incr_lbl(lbl_ary,level-1).join('.');// numbered heading labels
553558
var num_lbl= $("<span/>").addClass("toc-item-num")
554559
.text(num_str).append('&nbsp;').append('&nbsp;');

0 commit comments

Comments
 (0)