Skip to content
Open
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
15 changes: 14 additions & 1 deletion nbextensions/toc.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,26 @@ toc.load_ipython_extension();
define(["require", "jquery", "base/js/namespace"], function (require, $, IPython) {
"use strict";

var rand = function() {
return Math.random().toString(36).substr(2); // remove `0.`
};

var make_link = function (h) {

var a = $("<a/>");
a.attr("href", '#' + h.attr('id'));


// get the text *excluding* the link text, whatever it may be
var hclone = h.clone();
hclone.children().remove();
a.text(hclone.text());

var newID = hclone.text().toLowerCase().replace(/[^\w ]+/g,'').replace(/ +/g,'-') + '_' + rand();


h.attr('id', newID);
a.attr("href", '#' + newID);

return a;
};

Expand Down