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: sidebar + html export #593

Merged
merged 7 commits into from
Jun 13, 2016
Merged

toc2: sidebar + html export #593

merged 7 commits into from
Jun 13, 2016

Conversation

jfbercher
Copy link
Member

@jfbercher jfbercher commented Apr 29, 2016

toc2: new features:

  1. sidebar
  2. html export
  3. Navigation menu

Sidebar

Triggered by @cqcn1991's discussion and work, cf discussion here, a sidebar option is added. The floating toc window can be dragged and docked as a left sidebar. The sidebar can be dragged out as a floating window. These different states are stored and restored when reloading the notebook.

demo

html export

Add html export capability via templates toc.tpl and toc2.tpl.
It is possible to export (most of) table of contents functionalities to html. The idea is to link a relevant part of the javascript
extension and the css, and add a small script in the html file. This is done using a template by

jupyter nbconvert FILE.ipynb --template toc

or

jupyter nbconvert FILE.ipynb --template toc2

For the first template (toc), the files toc2.js and main.css (originally located in JUPYTER_DATA_DIR/nbextensions/usability/toc2) must reside in the same directory as intended for the html file. In the second template, these files are linked to the IPython-notebook-extensions github website. Export configuration (parameters) shall be edited directly in the template files (in templates directory JUPYTER_DATA_DIR/templates).

A "Save as HTML (with toc)" option is also available in the File menu and enable to directly convert the actual notebook. This option requires the IPython kernel and is not present with other kernels. I was not able to find a way to do it for other kernels (even with a customized exporter called from js).

 Navigation menu

since I realized that it is not difficult to add menus elements, I had the idea of adding a navigation menu". This menu can live together with the floating window or sidebar. It can be enabled/disabled using the nbextension configuration utility (enabled by default).

demo2

@jankatins
Copy link
Member

This looks great!

@jcb91
Copy link
Member

jcb91 commented Apr 29, 2016

Boss! This sounds fantastic :)
On 29 Apr 2016 5:49 p.m., "jfbercher" notifications@github.com wrote:

New features:

  1. sidebar
  2. html export

Sidebar

Triggered by @cqcn1991 https://github.com/cqcn1991's discussion and
work, cf discussion here
#532,
a sidebar option is added. The floating toc window can be dragged and
docked as a left sidebar. The sidebar can be dragged out as a floating
window. These different states are stored and restored when reloading the
notebook.

[image: demo]
https://cloud.githubusercontent.com/assets/7596356/14922916/8999462a-0e3a-11e6-8e96-17ddf73d64e1.gif
html export

Add html export capability via templates toc.tpl and toc2.tpl.
It is possible to export (most of) table of contents functionalities to
html. The idea is to link a relevant part of the javascript
extension and the css, and add a small script in the html file. This is
done using a template by

jupyter nbconvert FILE.ipynb --template toc

or

jupyter nbconvert FILE.ipynb --template toc2

For the first template (toc), the files toc2.js and main.css (originally
located in JUPYTER_DATA_DIR/nbextensions/usability/toc2) must reside in the
same directory as intended for the html file. In the second template, these
files are linked to the IPython-notebook-extensions github website. Export
configuration (parameters) shall be edited directly in the template files

(in templates directory JUPYTER_DATA_DIR/templates).

You can view, comment on, or merge this pull request online at:

#593
Commit Summary

  • toc2: sidebar + html export

File Changes

Patch Links:

https://github.com/ipython-contrib/IPython-notebook-extensions/pull/593.patch

https://github.com/ipython-contrib/IPython-notebook-extensions/pull/593.diff


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#593

@jankatins
Copy link
Member

jankatins commented Apr 29, 2016

Unfortunately, here the sidebar feature doesn't work as advertised: it clings to the side (and jumps to the top left position when I come near the left side), but is not displayed as a sidebar but still as a floating window:

sidebar

The feature is enabled (IMO that could be enabled as a default: I had to manually click it...)

Chrome, windows 7

@jfbercher
Copy link
Member Author

Stange. It seems that a style is missing. Have you downloaded/updated main.css? Can you have a look at the console output?

@jankatins
Copy link
Member

@jfbercher There isn't an error in the console. I use the table beautifier. I reinstalled the package via python setup.py install and I pressed a few times F5 in the opend notebook. Also, chrom tells me that the toc2/main.css file has .float-wrapper { in line 33, so it seems to be updated.

@jfbercher
Copy link
Member Author

It works for me in linux debian. I just ckecked with a fresh install on windows 8, anaconda, chome and it also works without any problem.
When dragging on the left side, toc should take the class ".sidebar-wrapper". Can you look at $('#toc-wrapper') in the console? Also can you start with an empty notebook?

@juhasch
Copy link
Member

juhasch commented Apr 29, 2016

Very nice, indeed!
I have a notebook where it works (i.e. the Jupyter example notebooks seem to work) and one that behaves like @JanSchulz describes.

Here is the notebook: https://gist.github.com/juhasch/c72e3d0fbb78bcea7cf0bc49e661e2c1
It also crashes Crome when changing a markdown cell.

@jfbercher
Copy link
Member Author

Can you @JanSchulz or @juhasch send me an example notebbok where the extension doesn't work? eg make a pull request at https://github.com/jfbercher/test and I will investigate. thxs

@juhasch
Copy link
Member

juhasch commented Apr 29, 2016

@jfbercher : See the link in my comment above

@jfbercher
Copy link
Member Author

jfbercher commented Apr 29, 2016

I think I got it.
It is a configuration issue (the toc config is copied from the config stored in notebooks, if it exists - in such a case, the key sidebar will not exist and yields this problem). I will update shortly.

@jfbercher
Copy link
Member Author

Changed reading of initial config. Hope this will fix. Thanks for the file @juhasch

@juhasch
Copy link
Member

juhasch commented Apr 29, 2016

Looks good, this fixes the docking issue.
Unfortunately, Chrome still crashes after changing a markdown cell when toc2 is loaded.

@jfbercher
Copy link
Member Author

Modified extension loading -- in some conditions, there was a recursive call of toc generation. Hope this fixes the hanging issue.

@cqcn1991
Copy link

This is fantastic. Great Work!
There is another thing I didn't mention, but it may simply the js code a little bit, making the original js file easier to maintain.

You can make the nestesd ordered list by pure css. No need to make the lable by js, see the second answer here.
http://stackoverflow.com/questions/2729927/number-nested-ordered-lists-in-html

@jfbercher
Copy link
Member Author

@cqcn1991 thanks. As for the css nested ordered lists tip, this deserve attention. But using such approach will affect our current unique ids generation. that relies on the items numbers.

Export: If anyone wants to test the html export feature, the current

jupyter nbconvert FILE.ipynb --template toc2

will only work (hopefully) after the PR is merged, because it uses links to the css and js files in the gitgub website. In order to test the functionality, I have added a toc2 template that links to my git account (I will remove it after). Testing can be done via

jupyter nbconvert FILE.ipynb --template toc3

@jankatins
Copy link
Member

work (hopefully) after the PR is merged, because it uses links to the css and js files in the gitgub website

Most of the rest of the css and js in a notebook are included, so I would prefer if this is included directly as well.,.. More or less that it would be easier to send html files to my advisor (but I think this isn't possible because require.js, mathjax and jquery are also loaded from a CDN)...

@cqcn1991
Copy link

cqcn1991 commented May 1, 2016

@JanSchulz That's how my original toy version works:
https://github.com/cqcn1991/sidepyter
You can just use the save as HTML in Jupyter Notebook, and the toc would be there. Just like this:
https://cdn.rawgit.com/cqcn1991/sidepyter/master/sidepyter_demo.html

If you really want it, you can try it.

I also made a auto ouput to HTML after running the Jupyter Notebook. If you want to know that, I can write about it.

@jankatins
Copy link
Member

JFYI: it works now :-) Thanks, this is great!

@jankatins
Copy link
Member

BTW: would it be possible to output the TOC cell as a proper markdown code instead of html? The links in that cell are currently not converted to pdf, so the toc is just for show, but not to be used to access the individual sections...

[ok, md links also don't work in PDF: https://github.com/jupyter/nbconvert/issues/11 Damn!]

@jankatins
Copy link
Member

jankatins commented May 2, 2016

Ok, one issue still [updated]in the versions of this PR[/]:

2016-05-02_142112

-> The scrollbar is at the bottom (=can't scroll down any down; some parts of the scrollbar are below the start menu!), but there is still some more headlines (12, 12.1 and 12.2). Could it be that it takes 100% of the page height, but as the page header already takes a few pixels, some of it is below the visible view port?

@cqcn1991
Copy link

cqcn1991 commented May 2, 2016

@JanSchulz I'm not sure if you are talking about my toy version, or @jfbercher 's official one.

My toy version have this problem. The root reason for this is the css layout setting at the notebook (jupyter/notebook#1202), so I haven't figure out a good way to deal with this.

I think your guess is correct. And that's why I set the height to be 95% insteand of 100%. But it seems still not working under all circunstances. A possible solution may be using jQuery to dynamically set the height, instead of using css to define the height.

@jankatins
Copy link
Member

@cqcn1991 Sorry, meant this PR -> updated my comment above...

@@ -146,26 +147,14 @@ define(["require", "jquery", "base/js/namespace", 'services/config',
$([IPython.events]).on("notebook_loaded.Notebook", function(){ // curiously, the event is not always fired or detected
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, the event is always fired, the issue is that depending on the notebook's complexity, the connection speed & lag time, it's possible for the notebook to load before the extension is loaded, in which case you miss the event.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thanks. I have realized that in the meantime.
Similarly, the kernel.ready event can also happen before the extension is fully loaded. In the last version, therefore, I load the stuff directly and only update things if these events occur.
@JanSchulz I will upload an update tomorrow for the hidden scrollbar issue.

@jfbercher
Copy link
Member Author

  • some fixes to sidebar (fixed the hidden scrollbar, here at least)
  • changed some styles for links in toc
  • added a "Save as HTML (with toc)
    file1
    available in the File menu and enable to directly convert the actual notebook. This option requires the IPython kernel and is not present with other kernels. I was not able to find a way to do it for other kernels (even with a customized exporter called from js).

Navigate menu

  • since I realized that it is not difficult to add menus elements, I had the idea of adding a navigation menu". This menu can live together with the floating window or sidebar. It can be enabled/disabled using the nbextension configuration utility (enabled by default).
    demo2

I hope that there are not to much errors. Please report.
But for now I really must go back to work...

There is a small issue at least with my latex_envs where all cells are refreshed at the startup. Since the building of the toc is fired each time a markdown cell renders, this adds some overload at startup (when latex_envs is loaded before toc2).

@cqcn1991
Copy link

cqcn1991 commented May 5, 2016

This is really good. Great work again, @jfbercher

@jcb91
Copy link
Member

jcb91 commented May 18, 2016

so are we ok to merge this?

@jankatins
Copy link
Member

I just tested it and apart from a different highlighter for the TOC entry (looks in my case like brown...), I really like it!

2016-05-18_141018

@cqcn1991
Copy link

cqcn1991 commented May 19, 2016

Just a simple thouht. As builders, some times we can build great features like this. But I'm afraid maybe we need to do more of this? There are a lot of people out there do not know the existence of this thing and other things.

@jfbercher
Copy link
Member Author

@JanSchulz You can change the background color in main.css
#toc-level0 li > a:hover { display: block; background-color: #DAA520}
eg something like { display: block; color: white; background-color: blue}
I am tired of the standard blue for links.
@cqcn1991 With the new mechanisms for nbextensions in 4.2 it would not be too difficult to transform it into a separate pip installable package (incorporating the dedicated toc2.py exporter I put in extensions). Unfortunately I will not be able to work on this before, say the end of june [and at this point I would like to rewrite the export part in latex_envs]. Furthermore, the toc2 source really needs a big cleanup, following all @jcb91 's goodies in his toc2_cleanup branch (do not remove it @jcb91 !). Any help/PR/contribution would be gladly received and appreciated.

@jankatins
Copy link
Member

jankatins commented May 22, 2016

One bad thing: if I have the toc activated (no matter if as sidebar or floating) and use RISE to display it as a slideshow, the sidebar is shown :-( Not sure what can be done here, but probably either we or RISE needs to set some css to hide the toc if the slideshow is active?

2016-05-22_224816

At leats the problem is gone if I deactivate the toc via the button...

CC: @damianavila

@jankatins
Copy link
Member

jankatins commented May 22, 2016

There seems to be another problem with RISE: if I have it as sidebar and disable it and then use RISE; the code area afterwards is moved to the left:
2016-05-22_230215

-> Could it be that the "disable" button does not remove all css?

@jankatins
Copy link
Member

In nbextension page, the last item has two dots:
2016-05-22_230536

```
jupyter nbconvert FILE.ipynb --template toc2
```
For the first template (toc), the files toc2.js and main.css (originally located in JUPYTER_DATA_DIR/nbextensions/usability/toc2) must reside in the same directory as intended for the html file. In the second template, these files are linked to the IPython-notebook-extensions github website. Export configuration (parameters) shall be edited directly in the template files (in templates directory JUPYTER_DATA_DIR/templates). An option "Save as HTML (with toc)" is also provided in the File menu and enable to directly convert the actual notebook. This option requires the IPython kernel and is not present with other kernels.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would there be a way to simply include these files in the template/final output? static one page files are best for sending this stuff to my adviser :-)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JanSchulz You just have to replace the link in the template by

{% include "FILENAME" ignore missing%}

This assumes that the file is in the same directory as the notebook (full paths do not work in jinja tempates).
I do not do it because anyway you still need an internet connection to get access to jquery. Please make a PR with an extra template if you want

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO the default should be to include stuff which is not on a CDN, so that sending the html file will work as long as a user has access to the internet... IMO the "toc must be on my drive" is useless because IMO html exports are to be exchanged with peers and so not on my drive. Or do I misunderstand anything here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps. You do not need to have toc or the notebook installed. Everything will work as long as the user has an internet access.
If you do not have access to internet, you will not have jquery and the toc javascript will not work. This is not true in the notebook since it has a copy of jquery inside. Otherwise you need to have an access to jquery, and most of the time this suppose an internet access.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You do not need to have toc or the notebook installed. Everything will work as long as the user has an internet access.

+1

@damianavila
Copy link
Member

Yep, RISE makes dirty things all over the place so it does not surprise me that there is a collision with other extensions like this one... one of my ideas for further RISE development is trying to isolate all the RISE-specific changes to avoid this kind of collisions... but not there yet...

@jfbercher
Copy link
Member Author

Perhaps would it be time to merge and let other users test and make issues/suggestions?

@jankatins
Copy link
Member

jankatins commented Jun 12, 2016

+1 on merging and iterating afterwards... I've run on this branch (only for the toc during interactive work, not the exports), and I didn't experience any problems.

@cqcn1991
Copy link

Would it be good if we can make a video or a gif demonstrate this and post it on sites like hackernews and some jupyter network?

@jcb91 jcb91 merged commit f7ad9bd into ipython-contrib:master Jun 13, 2016
@jcb91
Copy link
Member

jcb91 commented Jun 13, 2016

as noted, this seems mature enough to merge, and iterate later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants