Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Sep 18, 2024
1 parent 05f6f11 commit 19fcd8c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
10 changes: 4 additions & 6 deletions nbconvert/exporters/templateexporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +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
)

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 @@ -686,5 +686,3 @@ def _init_resources(self, resources):
resources["deprecated"] = deprecated
resources["include_tableofcontents"] = self.include_tableofcontents
return resources


11 changes: 8 additions & 3 deletions nbconvert/filters/markdown_mistune.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ def render(self, source: str) -> str:
"""Render the HTML output for a Markdown source."""
return str(super().__call__(source))


def markdown2html_mistune(source: str) -> str:
"""Convert a markdown string to HTML using mistune"""
return MarkdownWithMath(renderer=IPythonRenderer(escape=False)).render(source)
Expand All @@ -500,6 +501,7 @@ def heading(self, text, level):
self.headings.append((level, text))
return "" # We return an empty string to avoid outputting the headings


def extract_titles_from_markdown_input(markdown_input):
# Markdown_input is a single string with all the markdown content concatenated
# Initiate list of titles
Expand All @@ -515,12 +517,15 @@ def extract_titles_from_markdown_input(markdown_input):
extract_titles(markdown_input)

# Extracted headings
for level, title in renderer.headings: # renderer.headings is an array for each markdown element
for (
level,
title,
) in renderer.headings: # renderer.headings is an array for each markdown element
children = title["children"]
attrs = title["attrs"]
raw_text = children[0]["raw"]
level = attrs["level"]
id = raw_text.replace(' ', '-')
href= "#" + id
id = raw_text.replace(" ", "-")
href = "#" + id
titles_array.append([level, raw_text, id, href])
return titles_array
2 changes: 1 addition & 1 deletion share/templates/lab/index.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ a.anchor-link {
{{text}}
</a>
</div>
{%- endif -%}
{%- endif -%}
{%- if level==2 -%}
<div class="jp-RenderedHTMLCommon jp-RenderedHTMLTOC-Item-h2">
<a href={{href}}>
Expand Down

0 comments on commit 19fcd8c

Please sign in to comment.