From 28089faf9a71bf45c064f8e3b1d8ec5e4529eafe Mon Sep 17 00:00:00 2001 From: Florence Haudin <99649086+HaudinFlorence@users.noreply.github.com> Date: Tue, 8 Oct 2024 00:38:34 +0200 Subject: [PATCH] Apply suggestions from code review Co-authored-by: martinRenou --- nbconvert/filters/markdown_mistune.py | 8 ++--- share/templates/lab/index.html.j2 | 50 +++++++-------------------- 2 files changed, 17 insertions(+), 41 deletions(-) diff --git a/nbconvert/filters/markdown_mistune.py b/nbconvert/filters/markdown_mistune.py index 46a87f436..d9ecf0c5e 100644 --- a/nbconvert/filters/markdown_mistune.py +++ b/nbconvert/filters/markdown_mistune.py @@ -506,16 +506,16 @@ def heading(self, text, level): def extract_titles_from_markdown_input(markdown_input): - """Create a Markdown parser with the HeadingExtractor renderer to collect all the headings of a notebook""" - """ The input argument is markdown_input that is a single string with all the markdown content concatenated """ - """ The output is an array containing information about the headings such as their level, their text content, an identifier and a href that can be used in case of html converter.s""" + """Create a Markdown parser with the HeadingExtractor renderer to collect all the headings of a notebook + The input argument is markdown_input that is a single string with all the markdown content concatenated + The output is an array containing information about the headings such as their level, their text content, an identifier and a href that can be used in case of html converter.s""" titles_array = [] renderer = HeadingExtractor() extract_titles = mistune.create_markdown(renderer=renderer) extract_titles(markdown_input) headings = renderer.headings - """ Iterate on all headings to get the necessary information on the various titles """ + # Iterate on all headings to get the necessary information on the various titles for __, title in headings: children = title["children"] attrs = title["attrs"] diff --git a/share/templates/lab/index.html.j2 b/share/templates/lab/index.html.j2 index 680116448..a9cb94ae9 100644 --- a/share/templates/lab/index.html.j2 +++ b/share/templates/lab/index.html.j2 @@ -181,48 +181,24 @@ a.anchor-link {
Table of contents
{%- for item in resources.tableofcontents -%} {%- set (level, text, id, href) = item -%} +
- -{{text}} - -
-{%- endif -%} -{%- if level==2 -%} -
- -{{text}} - -
-{%- endif -%} -{%- if level==3 -%} -
- -{{text}} - -
-{%- endif -%} -{%- if level==4 -%} -
- -{{text}} - -
+class="jp-RenderedHTMLCommon jp-RenderedHTMLTOC-Item-h1" +{%- elif level==2 -%} +class="jp-RenderedHTMLCommon jp-RenderedHTMLTOC-Item-h2" +{%- elif level==3 -%} +class="jp-RenderedHTMLCommon jp-RenderedHTMLTOC-Item-h3" +{%- elif level==4 -%} +class="jp-RenderedHTMLCommon jp-RenderedHTMLTOC-Item-h4" +{%- elif level==5 -%} +class="jp-RenderedHTMLCommon jp-RenderedHTMLTOC-Item-h5" +{%- elif level==6 -%} +class="jp-RenderedHTMLCommon jp-RenderedHTMLTOC-Item-h6" {%- endif -%} -{%- if level==5 -%} -
+>
{{text}} - -{%- endif -%} -{%- if level==6 -%} -
- -{{text}} - -
-{%- endif -%} {%- endfor -%} {%- endif -%} {% endblock tableofcontents %}