diff --git a/nbconvert/exporters/templateexporter.py b/nbconvert/exporters/templateexporter.py index 9893b5fc3..0b8c27f41 100644 --- a/nbconvert/exporters/templateexporter.py +++ b/nbconvert/exporters/templateexporter.py @@ -683,9 +683,7 @@ def _init_resources(self, resources): resources["include_tableofcontents"] = self.include_tableofcontents return resources - def include_tableofcontents(self, resources): - # if len(resources["tableofcontents"])>0: + def include_tableofcontents(self): return True - - # else: - # return False + + diff --git a/share/templates/base/null.j2 b/share/templates/base/null.j2 index 547ddb458..929b18759 100644 --- a/share/templates/base/null.j2 +++ b/share/templates/base/null.j2 @@ -21,9 +21,10 @@ calling super. consider calling super even if it is a leaf block, we might insert more blocks later. #} +{%- block header -%} +{%- endblock header -%} {%- block body -%} {%- block body_header -%} -
{{"Hello \n\"World\""}}
{%- endblock body_header -%} {%- block body_loop -%} {%- for cell in nb.cells -%} diff --git a/share/templates/lab/base.html.j2 b/share/templates/lab/base.html.j2 index b4001ea2c..db0a879f9 100644 --- a/share/templates/lab/base.html.j2 +++ b/share/templates/lab/base.html.j2 @@ -2,10 +2,9 @@ {% from 'celltags.j2' import celltags %} {% from 'cell_id_anchor.j2' import cell_id_anchor %} -{% block tableofcontents %} -
{{"Table of contents"}}
+{%- block body_header -%} +{%- endblock body_header -%} -{% endblock tableofcontents %} {% block codecell %} {%- if not cell.outputs -%} diff --git a/share/templates/lab/index.html.j2 b/share/templates/lab/index.html.j2 index ad184ca7c..f19f0defc 100644 --- a/share/templates/lab/index.html.j2 +++ b/share/templates/lab/index.html.j2 @@ -126,6 +126,28 @@ a.anchor-link { {% endif %}
+{%- for item in resources.tableofcontents -%} +{%- set (level, text) = item -%} +{%- if level==1 -%} +

{{text}}

+{%- endif -%} +{%- if level==2 -%} +

{{text}}

+{%- endif -%} +{%- if level==3 -%} +

{{text}}

+{%- endif -%} +{%- if level==4 -%} +

{{text}}

+{%- endif -%} +{%- if level==5 -%} +
{{text}}
+{%- endif -%} +{%- if level==6 -%} +
{{text}}
+{%- endif -%} +{%- endfor -%} + {%- endblock body_header -%} {% block body_footer %}