Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toc2 -- Full url in links | #skip tag to skip headers from being inserted #1030

Merged
merged 3 commits into from
Jul 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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