kmahelona / ipython_notebook_goodies

Random goodies for use in iPython Notebooks
156 stars 47 forks source link

Port to jupyterlab? #6

Open lambdamusic opened 5 years ago

lambdamusic commented 5 years ago

Unfortunately this doesn't work out of the box with jupyterlab (see https://github.com/jupyterlab/jupyterlab/issues/1818).

I managed go get the script to load by first loading jquery like this

%%javascript
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = 'https://code.jquery.com/jquery-3.4.1.min.js';
    document.head.appendChild(script);

And then

%%javascript  $.getScript('https://kmahelona.github.io/ipython_notebook_goodies/ipython_notebook_toc.js')

However the TOC is not correct. The markdown headers from all the notebooks I have open (in different tabs) are meshed together.

Haven't had time to debug it properly.. maybe you have some ideas though :-)

kmahelona commented 5 years ago

You mean that your ToC on one webpage/tab contains items from other notebooks you have open in other tabs? That’s bizarre. I haven’t used the notebook for years - before it was jupyter - so I’m not sure what’s going on.

kmahelona commented 5 years ago

Maybe modifying the selector? Currently it’s set to ‘:header’.

https://github.com/kmahelona/ipython_notebook_goodies/blob/aaefb28c21c12237a10f9bd7dff9723feb084391/ipython_notebook_toc.js#L22

kmahelona commented 5 years ago

Also it would be easy to update the code to not use JQuery.

haskankaya commented 3 years ago

Bringing up an old thread, but just wanted to comment that the above solution posted by @lambdamusic has worked well for me.

I did get the same issue that they noted (headers from all the notebooks I have open (in different tabs) are meshed together), or something similar - but I found that when I exported the notebook as .html this issue was not there - it only contained the headings from my notebook. For me, this is the desired function so I'm happy with it.

I would recommend moving @lambdamusic 's solution into the README file with a notice to Jupyter Lab users, as this getting more popular than Notebook.