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

nbextensions and nbconvert #847

Open
tarokiritani opened this issue Jan 20, 2017 · 13 comments
Open

nbextensions and nbconvert #847

tarokiritani opened this issue Jan 20, 2017 · 13 comments

Comments

@tarokiritani
Copy link

Is it possible to use nbextensions with nbconvert? I ran jupyter nbconvert --to html nynotebook.ipynb. Then, toc2 seems to be effective in the resulting html. However, collapsible headings is no longer working.

Based on the previous issue #198, I understand that in order to use nbextensions with nbconvert I need to

  1. make "jupyter_nbconvert_config.py" in jupyter configuration folder (in my win 8.1, User.jupyter),
  2. put nbextension .py files in extensions folder, and
  3. I somehow need to write a template file in User.jupyter\extensions.

Am I mistaken? I have not found collapsible_headings.py in my env, and have not figured out the format of the template file. Could anyone give me pointers?

@jcb91
Copy link
Member

jcb91 commented Jan 20, 2017

Is it possible to use nbextensions with nbconvert?

Some of them support nbconvert, to various degrees. This is down to which have had templates, exporters etc written for them. See jupyter-contrib-nbextensions.readthedocs.io/en/latest/exporting for docs on the subject.

Based on the previous issue #198, I understand that in order to use nbextensions with nbconvert I need to [...] Am I mistaken?

Well, that advice is a little out of date, and a lot of that process is now done automatically by the package installation. Again, refer to the docs at jupyter-contrib-nbextensions.readthedocs.io/en/latest/exporting for the latest info.

I ran jupyter nbconvert --to html nynotebook.ipynb. Then, toc2 seems to be effective in the resulting html. However, collapsible headings is no longer working

I'm not completely familiar with how toc2 might function even without extra options passed to nbconvert, although I know it does provide an exporter for embedding into html output (see http://jupyter-contrib-nbextensions.readthedocs.io/en/latest/exporting.html#export-table-of-contents). The support for collapsible_headings exports is currently very limited (essentially, it'll just remove any hidden cells from the output), basically because I haven't written a version which can be embedded yet. Since you sound like you might use it, I'll give it some thought to it & see what I can come up with...

@tarokiritani
Copy link
Author

That would be great. This feature is very useful to read my long notebook. I just wrote a makeshift jquery script and put it in my notebook as a raw nbconvert script. I will use this for now. https://gist.github.com/tarokiritani/b1b5fefa5f19e57f107bd1c3b16c742a

@kikocorreoso
Copy link

Today I was thinking on this, a way to make a composable conversion, i.e., to export using TOC2, hidden cells,..., without conflicts between them.

Any idea or hint about how to start? A switch on a template? e.g.:

{% block whatever %}
  {% if TOC %}
    {# ... #}
  {% endif %}
{ % endblock %}

Should be a defined way to do so? I'm thinking in exporting notebooks to blogpost or standalone web pages but maintining some of the interactive functionality (TOC, widgets, some ad-hoc js to hide-show code cells, collapse sections, add styles based on the chosen options of the conversion,...).

Is there a roadmap for this?

@jfbercher
Copy link
Member

jfbercher commented Jan 23, 2017

@kikocorreoso Normally there is no reason to have conflicts between these various extensions. The templates can inherit from other templates; which means that you can chain several templates, eg toc2.tpl, nbextensions.tpl [which I think includes the older hide_input.tpl/hide_input_output.tpl templates].
I am not a specialist at all, but if you want to add switches in your jinja2 template, I think that you will have to write a preprocessor or an exporter, and pass variables either in the resources dictionary, or in the global environment, see eg https://github.com/jfbercher/jupyter_latex_envs/blob/master/src/latex_envs/latex_envs.py#L71-L73 and https://github.com/jfbercher/jupyter_latex_envs/blob/master/src/latex_envs/latex_envs.py#L284-L285.
I used the last one to include a new function in the jinja2 template, see https://github.com/jfbercher/jupyter_latex_envs/blob/master/src/latex_envs/latex_envs.py#L212-L224

@juhasch
Copy link
Member

juhasch commented Jan 23, 2017

I have added a description of nbextensions.tplin #850

@jcb91
Copy link
Member

jcb91 commented Jan 23, 2017 via email

@kikocorreoso
Copy link

thanks @jfbercher @juhasch @jcb91 for all the valuable suggestions, PR and for pointing me to some valid resources.

@jcb91
Copy link
Member

jcb91 commented Feb 15, 2017

I've added proper html-export capability for collapsible_headings in #892. However, given the export mechanism, it's not currently possible to support exports to both collapsible_headings and toc2 at the same time (not that difficult to fix though, I think, if people think it useful)

@psychemedia
Copy link

I've recently been exploring the use of the code prettifier extension, and it strikes me that this is another extension that could be valuable as an nbconvert cell processor, eg for tidying up a set of notebooks to make sure the code cells are styled consistently.

Anyone know of a snippet that demonstrates how this can be done? (i.e. how to invoke the code prettifier in the context of nbconvert?)

@thatlittleboy
Copy link

@jcb91 hi, thanks for your work on collapsible_headings. I came across this thread looking for a way to combine the collapsible_headings and toc2 extensions into my html export of my Jupyter notebook (exactly as you said).
Has there been any progress since then?

Now both extensions have support for an exporter:

jupyter nbconvert --to html_ch *.ipynb
jupyter nbconvert --to html_toc *.ipynb 

What's the proper way to do the export if I want both extensions?

Thank you.

@Dekermanjian
Copy link

@thatlittleboy Hi, did you ever figure out how to include both toc2 and collapsible_headings in your html export?

@thatlittleboy
Copy link

@Dekermanjian No I didn't, I just went with toc2 and forgo-ed collapsible_headings.

@Dekermanjian
Copy link

@thatlittleboy Alright, I guess the functionality isn't there yet. Thank you for the quick response.

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

No branches or pull requests

8 participants