Skip to content

Commit 27b3b42

Browse files
committed
[toc2] use <a class="tocSkip"> to skip headers from being inserted in toc, cf #1027
1 parent e627dfc commit 27b3b42

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -550,9 +550,9 @@ var table_of_contents = function (cfg,st) {
550550
if (h.id=="Table-of-Contents"){ return; }
551551
//If h had already a number, remove it
552552
$(h).find(".toc-item-num").remove();
553-
// skip header if tag #skip is present
554-
if (h.id.search('#skip') !== -1 ) {
555-
$(h).text($(h).text().replace("#skip", ""));
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 ) {
556556
return; }
557557
var num_str= incr_lbl(lbl_ary,level-1).join('.');// numbered heading labels
558558
var num_lbl= $("<span/>").addClass("toc-item-num")

0 commit comments

Comments
 (0)