Skip to content

Commit 05f6f11

Browse files
Add the include_tableofcontents traitlet and update the jinja template accordingly.
1 parent 0d02f38 commit 05f6f11

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

nbconvert/exporters/templateexporter.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@ def default_config(self):
203203
enable_async = Bool(False, help="Enable Jinja async template execution").tag(
204204
affects_environment=True
205205
)
206+
207+
include_tableofcontents = Bool(False, allow_none=True, help="Enable to include a table of contents").tag(
208+
config=True, affects_template=True
209+
)
206210

207211
_last_template_file = ""
208212
_raw_template_key = "<memory>"
@@ -683,7 +687,4 @@ def _init_resources(self, resources):
683687
resources["include_tableofcontents"] = self.include_tableofcontents
684688
return resources
685689

686-
def include_tableofcontents(self):
687-
return True
688-
689690

share/templates/lab/index.html.j2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ a.anchor-link {
177177
{% endif %}
178178
<main>
179179
{%- block tableofcontents -%}
180+
{%- if resources.include_tableofcontents -%}
180181
<div class="jp-RenderedHTMLTOC-Title">Table of contents</div>
181182
{%- for item in resources.tableofcontents -%}
182183
{%- set (level, text, id, href) = item -%}
@@ -223,6 +224,7 @@ a.anchor-link {
223224
</div>
224225
{%- endif -%}
225226
{%- endfor -%}
227+
{%- endif -%}
226228
{% endblock tableofcontents %}
227229
{%- endblock body_header -%}
228230

0 commit comments

Comments
 (0)