From 05f6f114bb302deef9609aceabd657ea630cf50b Mon Sep 17 00:00:00 2001 From: HaudinFlorence Date: Wed, 18 Sep 2024 11:56:23 +0200 Subject: [PATCH] Add the include_tableofcontents traitlet and update the jinja template accordingly. --- nbconvert/exporters/templateexporter.py | 7 ++++--- share/templates/lab/index.html.j2 | 2 ++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/nbconvert/exporters/templateexporter.py b/nbconvert/exporters/templateexporter.py index 0b8c27f41..6b1d66202 100644 --- a/nbconvert/exporters/templateexporter.py +++ b/nbconvert/exporters/templateexporter.py @@ -203,6 +203,10 @@ def default_config(self): enable_async = Bool(False, help="Enable Jinja async template execution").tag( affects_environment=True ) + + include_tableofcontents = Bool(False, allow_none=True, help="Enable to include a table of contents").tag( + config=True, affects_template=True + ) _last_template_file = "" _raw_template_key = "" @@ -683,7 +687,4 @@ def _init_resources(self, resources): resources["include_tableofcontents"] = self.include_tableofcontents return resources - def include_tableofcontents(self): - return True - diff --git a/share/templates/lab/index.html.j2 b/share/templates/lab/index.html.j2 index b69e7e976..f826b7b9f 100644 --- a/share/templates/lab/index.html.j2 +++ b/share/templates/lab/index.html.j2 @@ -177,6 +177,7 @@ a.anchor-link { {% endif %}
{%- block tableofcontents -%} +{%- if resources.include_tableofcontents -%} {%- for item in resources.tableofcontents -%} {%- set (level, text, id, href) = item -%} @@ -223,6 +224,7 @@ a.anchor-link { {%- endif -%} {%- endfor -%} +{%- endif -%} {% endblock tableofcontents %} {%- endblock body_header -%}