diff --git a/nbconvert/exporters/html.py b/nbconvert/exporters/html.py
index 89a3558e7..5c6f6c478 100644
--- a/nbconvert/exporters/html.py
+++ b/nbconvert/exporters/html.py
@@ -265,9 +265,8 @@ def from_notebook_node( # type:ignore[explicit-override, override]
if cell.cell_type == "markdown":
markdown_collection = markdown_collection + cell.source + "\n"
- resources["tableofcontents"] = extract_titles_from_markdown_input(markdown_collection)
-
resources = self._init_resources(resources)
+ resources.update({"tableofcontents": extract_titles_from_markdown_input(markdown_collection)})
filter_data_type = WidgetsDataTypeFilter(
notebook_metadata=self._nb_metadata, parent=self, resources=resources
diff --git a/nbconvert/exporters/slides.py b/nbconvert/exporters/slides.py
index e571a90c0..62a11402b 100644
--- a/nbconvert/exporters/slides.py
+++ b/nbconvert/exporters/slides.py
@@ -41,7 +41,7 @@ def preprocess(self, nb, resources=None):
in_fragment = False
- for index, cell in enumerate(nb.cells[first_slide_ix + 1 :], start=(first_slide_ix + 1)):
+ for index, cell in enumerate(nb.cells[first_slide_ix + 1:], start=(first_slide_ix + 1)):
previous_cell = nb.cells[index - 1]
# Slides are elements in the HTML, subslides (the vertically
diff --git a/nbconvert/exporters/templateexporter.py b/nbconvert/exporters/templateexporter.py
index 6b1d66202..0f551b069 100644
--- a/nbconvert/exporters/templateexporter.py
+++ b/nbconvert/exporters/templateexporter.py
@@ -203,9 +203,8 @@ 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
+ config=True, affects_template=True
)
_last_template_file = ""
@@ -289,8 +288,7 @@ def _template_extension_default(self):
).tag(config=True)
exclude_output = Bool(
- False,
- help="This allows you to exclude code cell outputs from all templates if set to True.",
+ False, help="This allows you to exclude code cell outputs from all templates if set to True.",
).tag(config=True)
exclude_output_prompt = Bool(
@@ -686,5 +684,3 @@ def _init_resources(self, resources):
resources["deprecated"] = deprecated
resources["include_tableofcontents"] = self.include_tableofcontents
return resources
-
-
diff --git a/nbconvert/filters/ansi.py b/nbconvert/filters/ansi.py
index a9882e10e..ac91fc89f 100644
--- a/nbconvert/filters/ansi.py
+++ b/nbconvert/filters/ansi.py
@@ -197,7 +197,7 @@ def _ansi2anything(text, converter):
pass # Invalid color specification
else:
pass # Not a color code
- chunk, text = text[: m.start()], text[m.end() :]
+ chunk, text = text[: m.start()], text[m.end():]
else:
chunk, text = text, ""
diff --git a/nbconvert/filters/citation.py b/nbconvert/filters/citation.py
index 0db092a42..e078ceed0 100644
--- a/nbconvert/filters/citation.py
+++ b/nbconvert/filters/citation.py
@@ -42,7 +42,7 @@ def citation2latex(s):
outtext = ""
startpos = 0
for citation in parser.citelist:
- outtext += s[startpos : citation[1]]
+ outtext += s[startpos: citation[1]]
outtext += "\\cite{%s}" % citation[0]
startpos = citation[2] if len(citation) == 3 else -1
outtext += s[startpos:] if startpos != -1 else ""
diff --git a/nbconvert/filters/markdown_mistune.py b/nbconvert/filters/markdown_mistune.py
index c1889f06e..64d19476e 100644
--- a/nbconvert/filters/markdown_mistune.py
+++ b/nbconvert/filters/markdown_mistune.py
@@ -385,7 +385,7 @@ def _embed_image_or_attachment(self, src: str) -> str:
attachment_prefix = "attachment:"
if src.startswith(attachment_prefix):
- name = src[len(attachment_prefix) :]
+ name = src[len(attachment_prefix):]
if name not in self.attachments:
msg = f"missing attachment: {name}"
@@ -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)
@@ -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
@@ -515,12 +517,12 @@ 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:
children = title["children"]
attrs = title["attrs"]
raw_text = children[0]["raw"]
- level = attrs["level"]
+ header_level = attrs["level"]
id = raw_text.replace(' ', '-')
- href= "#" + id
- titles_array.append([level, raw_text, id, href])
+ href = "#" + id
+ titles_array.append([header_level, raw_text, id, href])
return titles_array
diff --git a/nbconvert/nbconvertapp.py b/nbconvert/nbconvertapp.py
index a16327345..d80339123 100755
--- a/nbconvert/nbconvertapp.py
+++ b/nbconvert/nbconvertapp.py
@@ -223,7 +223,7 @@ def _classes_default(self):
return classes
- description = Unicode(# type:ignore[assignment]
+ description = Unicode( # type:ignore[assignment]
"""This application is used to convert notebook files (*.ipynb)
to various other formats.
@@ -342,7 +342,7 @@ def _postprocessor_class_changed(self, change):
if new:
self.postprocessor_factory = import_item(new)
- export_format = Unicode(# type:ignore[call-overload]
+ export_format = Unicode( # type:ignore[call-overload]
allow_none=False,
help=f"""The export format to be used, either one of the built-in formats
{get_export_names()}
diff --git a/tests/base.py b/tests/base.py
index ff2bec3d5..d854900a8 100644
--- a/tests/base.py
+++ b/tests/base.py
@@ -176,15 +176,15 @@ def assert_big_text_equal(a, b, chunk_size=80):
to give better info than vanilla assertEqual for large text blobs.
"""
for i in range(0, len(a), chunk_size):
- chunk_a = a[i : i + chunk_size]
- chunk_b = b[i : i + chunk_size]
+ chunk_a = a[i: i + chunk_size]
+ chunk_b = b[i: i + chunk_size]
assert chunk_a == chunk_b, "[offset: %i]\n%r != \n%r" % (i, chunk_a, chunk_b)
if len(a) > len(b):
raise AssertionError(
- "Length doesn't match (%i > %i). Extra text:\n%r" % (len(a), len(b), a[len(b) :])
+ "Length doesn't match (%i > %i). Extra text:\n%r" % (len(a), len(b), a[len(b):])
)
if len(a) < len(b):
raise AssertionError(
- "Length doesn't match (%i < %i). Extra text:\n%r" % (len(a), len(b), a[len(b) :])
+ "Length doesn't match (%i < %i). Extra text:\n%r" % (len(a), len(b), a[len(b):])
)