-
Notifications
You must be signed in to change notification settings - Fork 806
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
jinja2.exceptions.TemplateNotFound: toc2 #1533
Comments
Smoke test changes include: * recent SQL from dataset builder for the dataset snippets smoke test setup * some naming consistency updates within the dataset snippets smoke test setup configuration * some conditional logic so that we do not attempt to render ipywidgets in the context of a smoke test * Also note that the newer version of `nbconvert` is incompatible with Jupyter extension `toc2`. * This causes the [HTML snapshot](https://github.com/all-of-us/workbench-snippets/tree/master/py#create-and-view-html-snapshots-of-notebooks) functionality to fail as the export format is `html_toc` which is provided by `toc2`. * See ipython-contrib/jupyter_contrib_nbextensions#1533 * For now we work around this by changing the export format to `html`.
is it any roadmap to update to nbconvert>6 |
seconded. would love if I could get the table of contents html export to work in nbconvert > 6. spent all day working on trying to create a custom exporter myself, but wasn't able to manage. |
I've been using this workaround reported by @elgalu, as there are still problems with toc export, even when using the version 5.3, that hasn't been officially published yet. I've written about the issues I got in the other topic related with TOC #1568 @deflaux |
@leodrivera I wouldn't know. I have not contributed to this repository. But whenever it is fixed, I look forward to using it again!! The TOC is so nice to have when the Jupyter notebooks exported to HTML are long. |
Indeed. As I usually write long notebooks, it makes so much easier for reading it. @deflaux I've looked at the last commits and I am pinging them, so maybe we can try to solve this together: |
maybe this patch to nbconvert can work: *** a/nbconvert/exporters/templateexporter.py 2020-11-07 12:54:46.000000000 +0800
--- b/nbconvert/exporters/templateexporter.py 2020-11-08 01:22:31.634876123 +0800
***************
*** 531,555 ****
--- 531,562 ----
# we include root_dir for when we want to be very explicit, e.g.
# {% extends 'nbconvert/templates/classic/base.html' %}
paths.append(root_dir)
# we include base_dir for when we want to be explicit, but less than root_dir, e.g.
# {% extends 'classic/base.html' %}
base_dir = os.path.join(root_dir, 'nbconvert', 'templates')
paths.append(base_dir)
+ compatibility_dir = os.path.join(root_dir, 'jupyter_contrib_nbextensions', 'templates')
+ paths.append(compatibility_dir)
+ compatibility_dir = os.path.join(root_dir, 'nbconvert', 'templates', 'base')
+ paths.append(compatibility_dir)
+ compatibility_dir = os.path.join(root_dir, 'nbconvert', 'templates', 'classic')
+ paths.append(compatibility_dir)
compatibility_dir = os.path.join(root_dir, 'nbconvert', 'templates', 'compatibility')
paths.append(compatibility_dir)
additional_paths = self.template_data_paths
for path in additional_paths:
try:
ensure_dir_exists(path, mode=0o700)
except OSError:
pass
+ #print("self.extra_template_basedirs:", self.extra_template_basedirs, self.extra_template_paths + additional_paths + paths)
return self.extra_template_paths + additional_paths + paths
@classmethod
def get_compatibility_base_template_conf(cls, name):
# Hard-coded base template confs to use for backwards compatibility for 5.x-only templates
if name == 'display_priority':
return dict(base_template='base') |
according to https://nbconvert.readthedocs.io/en/latest/external_exporters.html#registering-a-custom-exporter-as-an-entry-point, you can also try: |
@cailiang9 Unfortunately, it did not solve for me. However, I could solve part of the problem by changing the files hosted in https://gitcdn.xyz/ (and substituting the path here) to the same files hosted in my personal github (inside github.io) and, after that, the js could be effectively loaded and the page appeared. But I still have those two issues:
|
I got toc2 rendered correctly in a notebook html in nbconvert <link rel="stylesheet" type="text/css" href="https://my.cdn.org/toc2/main.css">
<script src="https://my.cdn.org/toc2/toc2.js"></script>
{
"base_template": "classic",
"mimetypes": {
"text/html": true
},
"preprocessors": {
"100-pygments": {
"type": "nbconvert.preprocessors.CSSHTMLHeaderPreprocessor",
"enabled": true
},
"500-reveal": {
"type": "nbconvert.exporters.slides._RevealMetadataPreprocessor",
"enabled": true
}
}
}
{%- extends 'classic/index.html.j2' -%}
{%- block html_head_js -%}
{%- block html_head_js_requirejs -%}
<script src="{{ resources.require_js_url }}"></script>
{%- endblock html_head_js_requirejs -%}
{%- block html_head_js_jquery -%}
<script src="{{ resources.jquery_url }}"></script>
{%- endblock html_head_js_jquery -%}
{%- endblock html_head_js -%} Here is my full working template, you only need to replace URLs for main.css and toc2.js - I don't want mine to be used elsewhere.
|
I still have the problem. I am trying your solution. In my installation, I find
which I replace exactly for 'https://replace.with.cdn/toc2/' in your I find
I think it is almost what you have done. I guess that your text beginning with
should go in some file named I found
I replace it by your I also change the first line of
Then the ouput of your program is:
The problem https://github.com/jupyter/nbconvert/issues/1394 has been solved. Then
and following the same principle as before add Similar correction needed for Next error:
I put
|
Spent a lot of time trying to get table of contents to work and just could not get it done. @Sieboldianus I added your This is what nbextensions configurator tab shows, and this is the notebook in question: Might be some weird install issue with $ pip list | grep -E 'nbconvert|jinja2|nbextension|jupyter
nbconvert 7.8.0
jupyter_client 7.4.9
jupyter-console 6.6.3
jupyter-contrib-core 0.4.0
jupyter-contrib-nbextensions 0.7.0
jupyter_core 5.3.0
jupyter-events 0.7.0
jupyter-highlight-selected-word 0.2.0
jupyter-latex-envs 1.4.6
jupyter-lsp 2.2.0
jupyter-nbextensions-configurator 0.6.1
jupyter_server 2.7.3
jupyter_server_fileid 0.9.0
jupyter_server_terminals 0.4.4
jupyter_server_ydoc 0.8.0
jupyter-ydoc 0.2.4
jupyterlab 3.6.5
jupyterlab-pygments 0.2.2
jupyterlab_server 2.25.0 |
Yes, this gets more and more complicated. My approach worked until last week, when These are my current versions:
Here are some links to get you started:
Some hints:
|
I struggled a lot combining all the knowledge in this thread for my case, but finally stumbled a working solution for my use case (using I'm working in an older conda environment with an older version of nbconvert Here are my steps (hoping this can help someone):
Resulting $HOME/custom-toc2/toc2.tpl (click to expand){%- extends 'nbextensions.tpl' -%}
{%- block header -%}
{{ super() }}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.css">
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/gh/ipython-contrib/jupyter_contrib_nbextensions@0.5.1/src/jupyter_contrib_nbextensions/nbextensions/toc2/main.css">
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://cdn.jsdelivr.net/gh/ipython-contrib/jupyter_contrib_nbextensions@0.5.1/src/jupyter_contrib_nbextensions/nbextensions/toc2/toc2.js"></script>
<script>
$( document ).ready(function(){
var cfg = {{ nb.get('metadata', {}).get('toc', {})|tojson|safe }};
cfg.navigate_menu=false;
// fire the main function with these parameters
require(['nbextensions/toc2/toc2'], function (toc2) {
toc2.table_of_contents(cfg);
});
});
</script>
{%- endblock header -%} Then finally, using the following command to convert my notebooks:
|
jinja2.exceptions.TemplateNotFound: toc2
failure after upgrading nbconvert >= 6How to reproduce
Error
Workaround
pip install "nbconvert<6"
The text was updated successfully, but these errors were encountered: