jckantor / nbpages

Command line tool to maintain a repository of Jupyter notebooks.
https://jckantor.github.io/nbpages/
MIT License
3 stars 4 forks source link

Possible bug in nbpages.tpl #25

Closed adowling2 closed 4 years ago

adowling2 commented 4 years ago

Below is output after adopting the changes in PR #24:

(base) esc306856:cbe67701-uncertainty-quantification adowling$ nbpages 
- inserting header for 01.00-Introduction-to-Uncertainty-Quantification-and-Predictive-Sciences.ipynb
- inserting header for 02.00-Probability-and-Statistics-Preliminaries.ipynb
- inserting header for 03.00-Input-Parameter-Distributions.ipynb
- inserting navbar for 01.00-Introduction-to-Uncertainty-Quantification-and-Predictive-Sciences.ipynb
- inserting navbar for 01.00-Introduction-to-Uncertainty-Quantification-and-Predictive-Sciences.ipynb
- inserting navbar for 02.00-Probability-and-Statistics-Preliminaries.ipynb
- inserting navbar for 02.00-Probability-and-Statistics-Preliminaries.ipynb
- inserting navbar for 03.00-Input-Parameter-Distributions.ipynb
- inserting navbar for 03.00-Input-Parameter-Distributions.ipynb
- writing table of contents file
[NbConvertApp] Converting notebook docs/toc.ipynb to html
[NbConvertApp] Writing 274340 bytes to docs/toc.html
- writing tag index file
[NbConvertApp] Converting notebook docs/tag_index.ipynb to html
[NbConvertApp] Writing 273413 bytes to docs/tag_index.html
- writing index.md
Traceback (most recent call last):
  File "/anaconda3/bin/nbpages", line 11, in <module>
    load_entry_point('nbpaages', 'console_scripts', 'nbpages')()
  File "/Users/adowling/DowlingLab/Teaching/nbpages/src/nbpages/__main__.py", line 98, in main
    notebooks.write_html(NOTEBOOK_DST_DIR, os.path.join("templates", 'nbpages.tpl'))
  File "/Users/adowling/DowlingLab/Teaching/nbpages/src/nbpages/nbcollection.py", line 464, in write_html
    (body, resources) = html_exporter.from_notebook_node(nb.content)
  File "/anaconda3/lib/python3.7/site-packages/nbconvert/exporters/html.py", line 96, in from_notebook_node
    output, resources = super(HTMLExporter, self).from_notebook_node(nb, resources, **kw)
  File "/anaconda3/lib/python3.7/site-packages/nbconvert/exporters/templateexporter.py", line 315, in from_notebook_node
    output = self.template.render(nb=nb_copy, resources=resources)
  File "/anaconda3/lib/python3.7/site-packages/nbconvert/exporters/templateexporter.py", line 113, in template
    self._template_cached = self._load_template()
  File "/anaconda3/lib/python3.7/site-packages/nbconvert/exporters/templateexporter.py", line 286, in _load_template
    return self.environment.get_template(template_file)
  File "/anaconda3/lib/python3.7/site-packages/jinja2/environment.py", line 830, in get_template
    return self._load_template(name, self.make_globals(globals))
  File "/anaconda3/lib/python3.7/site-packages/jinja2/environment.py", line 804, in _load_template
    template = self.loader.load(self, name, globals)
  File "/anaconda3/lib/python3.7/site-packages/jinja2/loaders.py", line 405, in load
    return loader.load(environment, name, globals)
  File "/anaconda3/lib/python3.7/site-packages/jinja2/loaders.py", line 125, in load
    code = environment.compile(source, name, filename)
  File "/anaconda3/lib/python3.7/site-packages/jinja2/environment.py", line 591, in compile
    self.handle_exception(exc_info, source_hint=source_hint)
  File "/anaconda3/lib/python3.7/site-packages/jinja2/environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/anaconda3/lib/python3.7/site-packages/jinja2/_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "/Users/adowling/DowlingLab/Teaching/cbe67701-uncertainty-quantification/templates/nbpages.tpl", line 15, in template
    {% endblock any
  File "/anaconda3/lib/python3.7/site-packages/jinja2/environment.py", line 497, in _parse
    return Parser(self, source, name, encode_filename(filename)).parse()
  File "/anaconda3/lib/python3.7/site-packages/jinja2/parser.py", line 901, in parse
    result = nodes.Template(self.subparse(), lineno=1)
  File "/anaconda3/lib/python3.7/site-packages/jinja2/parser.py", line 888, in subparse
    self.stream.expect('block_end')
  File "/anaconda3/lib/python3.7/site-packages/jinja2/lexer.py", line 384, in expect
    self.name, self.filename)
jinja2.exceptions.TemplateSyntaxError: expected token 'end of statement block', got 'any'

Here are the contents of templates/nbpages.tpl:

<!-- jinja2 template that extendes `full` to add cell tags in the html rendering of notebooks -->
{% extends 'full.tpl'%}
{% block any_cell %}
{% if cell['metadata'].get('tags', []) %}
    <div style="background-color:white; border:thin solid grey; margin-left:95px; margin-right:6px">
    {% for tag in cell['metadata'].get('tags', []) %}
        &nbsp; <a href="https://{github_user_name}.github.io/{github_repo_name}/tag_index.html#{{ tag }}">{{ tag }}</a>
    {% endfor %}
    </div>
    {{ super() }}
{% else %}
    {{ super() }}
{% endif %}
{% endblock any
adowling2 commented 4 years ago

Changing the last line of templates/nbpages.tpl to {% endblock %} fixed the problem.

adowling2 commented 4 years ago

I just checked the default template in the master branch. The last line should be {% endblock any_cell %}. Perhaps I accidentally deleted %} on the last line.