Skip to content

Commit

Permalink
Add the include_tableofcontents traitlet and update the jinja templat…
Browse files Browse the repository at this point in the history
…e accordingly.
  • Loading branch information
HaudinFlorence committed Sep 18, 2024
1 parent 0d02f38 commit 05f6f11
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 4 additions & 3 deletions nbconvert/exporters/templateexporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<memory>"
Expand Down Expand Up @@ -683,7 +687,4 @@ def _init_resources(self, resources):
resources["include_tableofcontents"] = self.include_tableofcontents
return resources

def include_tableofcontents(self):
return True


2 changes: 2 additions & 0 deletions share/templates/lab/index.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ a.anchor-link {
{% endif %}
<main>
{%- block tableofcontents -%}
{%- if resources.include_tableofcontents -%}
<div class="jp-RenderedHTMLTOC-Title">Table of contents</div>
{%- for item in resources.tableofcontents -%}
{%- set (level, text, id, href) = item -%}
Expand Down Expand Up @@ -223,6 +224,7 @@ a.anchor-link {
</div>
{%- endif -%}
{%- endfor -%}
{%- endif -%}
{% endblock tableofcontents %}
{%- endblock body_header -%}

Expand Down

0 comments on commit 05f6f11

Please sign in to comment.