From 995696e3bf073ba250460f1bed38d8e4e51153fb Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 4 Oct 2024 14:18:01 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- nbconvert/exporters/html.py | 4 +++- nbconvert/exporters/templateexporter.py | 10 ++++------ nbconvert/filters/markdown_mistune.py | 11 ++++++++--- nbconvert/nbconvertapp.py | 13 +++++-------- share/templates/lab/index.html.j2 | 2 +- share/templates/latex/base.tex.j2 | 2 +- 6 files changed, 22 insertions(+), 20 deletions(-) diff --git a/nbconvert/exporters/html.py b/nbconvert/exporters/html.py index 5c6f6c478..a9afb1475 100644 --- a/nbconvert/exporters/html.py +++ b/nbconvert/exporters/html.py @@ -266,7 +266,9 @@ def from_notebook_node( # type:ignore[explicit-override, override] markdown_collection = markdown_collection + cell.source + "\n" resources = self._init_resources(resources) - resources.update({"tableofcontents": extract_titles_from_markdown_input(markdown_collection)}) + 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/templateexporter.py b/nbconvert/exporters/templateexporter.py index 6b1d66202..2575af427 100644 --- a/nbconvert/exporters/templateexporter.py +++ b/nbconvert/exporters/templateexporter.py @@ -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 = "" @@ -686,5 +686,3 @@ def _init_resources(self, resources): resources["deprecated"] = deprecated resources["include_tableofcontents"] = self.include_tableofcontents return resources - - diff --git a/nbconvert/filters/markdown_mistune.py b/nbconvert/filters/markdown_mistune.py index c1889f06e..a79ed635e 100644 --- a/nbconvert/filters/markdown_mistune.py +++ b/nbconvert/filters/markdown_mistune.py @@ -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,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 diff --git a/nbconvert/nbconvertapp.py b/nbconvert/nbconvertapp.py index a16327345..1ba7bec05 100755 --- a/nbconvert/nbconvertapp.py +++ b/nbconvert/nbconvertapp.py @@ -187,12 +187,8 @@ def validate(self, obj, value): """Whether the HTML in Markdown cells and cell outputs should be sanitized..""", ), "toc": ( - { - "TemplateExporter": { - "include_tableofcontents": True - } - }, - "Generate a table of contents in the output (only compatible with HTML and Latex exporters)" + {"TemplateExporter": {"include_tableofcontents": True}}, + "Generate a table of contents in the output (only compatible with HTML and Latex exporters)", ), } ) @@ -223,7 +219,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 +338,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()} @@ -678,6 +674,7 @@ def initialize(self, argv=None): def _default_export_format(self): return "html" + # ----------------------------------------------------------------------------- # Main entry point # ----------------------------------------------------------------------------- diff --git a/share/templates/lab/index.html.j2 b/share/templates/lab/index.html.j2 index f826b7b9f..680116448 100644 --- a/share/templates/lab/index.html.j2 +++ b/share/templates/lab/index.html.j2 @@ -187,7 +187,7 @@ a.anchor-link { {{text}} -{%- endif -%} +{%- endif -%} {%- if level==2 -%}
diff --git a/share/templates/latex/base.tex.j2 b/share/templates/latex/base.tex.j2 index 337aa09c1..6ece1adab 100644 --- a/share/templates/latex/base.tex.j2 +++ b/share/templates/latex/base.tex.j2 @@ -213,7 +213,7 @@ override this.-=)) ((* endblock header *)) ((* block body *)) - + \begin{document} ((* block predoc *)) ((* block maketitle *))\maketitle((* endblock maketitle *))