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: html export -- take into account number_section #810

Merged
merged 3 commits into from
Dec 3, 2016

Conversation

jfbercher
Copy link
Member

OK, here is a possibility to address #808
Just read the parameter in notebook's metadata and populate the parameter in the export template.

However, this has a drawback and I am not sure that it should be merged: if the metadata toc (the toc section in metadata) does not exist, then conversion fail; even if we try to catch the exception; since actually the exception arises in the jinja2 processing.
I think that it can be useful to convert notebook using the html_tocparameter even if they have not be created with toc2 activated, since it still generates the toc in that case. Thoughts?

@jcb91
Copy link
Member

jcb91 commented Nov 30, 2016

I think that it can be useful to convert notebook using the html_tocparameter even if they have not be created with toc2 activated, since it still generates the toc in that case.

Yes, sounds reasonable.

if the metadata toc (the toc section in metadata) does not exist, then conversion fail; even if we try to catch the exception; since actually the exception arises in the jinja2 processing.

This can be avoided with robust jinja processing, though, right?

@@ -16,7 +16,7 @@
<script>
$( document ).ready(function(){
var cfg={'threshold':6, // depth of toc (number of levels)
'number_sections':true, // sections numbering
'number_sections': "{{nb['metadata']['toc']['number_sections']}}"=="True" ? true : false, // sections numbering
Copy link
Member

Choose a reason for hiding this comment

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

it would probably be more robust to use something like

'number_sections': {{ 'true' if nb.get('metadata', {}).get('toc', {}).get('number_sections', False) else 'false' }},

Copy link
Member Author

Choose a reason for hiding this comment

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

Wow. Very nice!

@NicolasWoloszko
Copy link

I have modified the toc2.tpl file on my laptop and implemented the change you suggested but i still have the same problem on export :
capture d ecran 2016-12-01 a 11 49 30

On the HTML file, the TOC has no indetation and is numbered although I desactivated the numbering parameter in the settings.

@jfbercher
Copy link
Member Author

@NicolasWoloszko You will have to re-install the jupyter_contrib_nbextensions once this will be merged since the templates are copied in a subdirectory of the python package (its exact location varies depending on the system you use). Otherwise make the modifications in the jupyter_contrib_nbextensions/.../templates directory and reinstall by python setup.py install and then step 2 in README, eg jupyter contrib nbextension install --user

@jfbercher
Copy link
Member Author

@NicolasWoloszko
Indentation I have checked and for me it works.
It seems that the css is not read/present. Actually, the css is read from the jupyter_contrib_nbextensions site. If you try to read your html file without internet connection, it would produce this effect. A possibility is to include the relevant style directly in the notebook: try to paste

%%HTML
<style>
.lev1 {margin-left: 80px}
.lev2 {margin-left: 100px}
.lev3 {margin-left: 120px}
.lev4 {margin-left: 140px}
.lev5 {margin-left: 160px}
.lev6 {margin-left: 180px}
</style>

in a code cell.

@NicolasWoloszko
Copy link

That's working thank you very much !

@jfbercher
Copy link
Member Author

toc2:

  • added reading of threshold (number of levels to number) and sidebar (display the sidebar or floating window) parameters from notebook metadata instead of using static defaults
  • included the css used for the "static toc cell" possibly included, in case it can't be read from main.css (no network connection)

@jcb91
Copy link
Member

jcb91 commented Dec 3, 2016

haha, let's merge now? We can always add further PRs later 😆

@jfbercher
Copy link
Member Author

Yes, we can merge now. I just wanted to finish the work to include the other parameters.

@jcb91
Copy link
Member

jcb91 commented Dec 3, 2016

yeah, sorry, it did make sense to include, I was just getting an itchy trigger finger, so to speak.

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.

3 participants