Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: martinRenou <martin.renou@gmail.com>
  • Loading branch information
HaudinFlorence and martinRenou authored Oct 7, 2024
1 parent b4d7e3d commit 28089fa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 41 deletions.
8 changes: 4 additions & 4 deletions nbconvert/filters/markdown_mistune.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
50 changes: 13 additions & 37 deletions share/templates/lab/index.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -181,48 +181,24 @@ a.anchor-link {
<div class="jp-RenderedHTMLTOC-Title">Table of contents</div>
{%- for item in resources.tableofcontents -%}
{%- set (level, text, id, href) = item -%}
<div
{%- if level==1 -%}
<div class="jp-RenderedHTMLCommon jp-RenderedHTMLTOC-Item-h1">
<a href={{href}}>
{{text}}
</a>
</div>
{%- endif -%}
{%- if level==2 -%}
<div class="jp-RenderedHTMLCommon jp-RenderedHTMLTOC-Item-h2">
<a href={{href}}>
{{text}}
</a>
</div>
{%- endif -%}
{%- if level==3 -%}
<div class="jp-RenderedHTMLCommon jp-RenderedHTMLTOC-Item-h3">
<a href={{href}}>
{{text}}
</a>
</div>
{%- endif -%}
{%- if level==4 -%}
<div class="jp-RenderedHTMLCommon jp-RenderedHTMLTOC-Item-h4">
<a href={{href}}>
{{text}}
</a>
</div>
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 -%}
<div class="jp-RenderedHTMLCommon jp-RenderedHTMLTOC-Item-h5">
></div>
<a href={{href}}>
{{text}}
</a>
</div>
{%- endif -%}
{%- if level==6 -%}
<div class="jp-RenderedHTMLCommon jp-RenderedHTMLTOC-Item-h6">
<a href={{href}}>
{{text}}
</a>
</div>
{%- endif -%}
{%- endfor -%}
{%- endif -%}
{% endblock tableofcontents %}
Expand Down

0 comments on commit 28089fa

Please sign in to comment.