From e4cef00a4341904fa65606a1aec367ac8bbdb80e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 7 Oct 2024 14:01:49 +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/slides.py | 2 +- nbconvert/exporters/templateexporter.py | 9 ++++--- nbconvert/filters/ansi.py | 2 +- nbconvert/filters/citation.py | 2 +- nbconvert/filters/markdown_mistune.py | 36 ++++++++++++------------- nbconvert/nbconvertapp.py | 9 +++---- share/templates/lab/index.html.j2 | 2 +- share/templates/latex/base.tex.j2 | 2 +- tests/base.py | 8 +++--- tests/exporters/test_html.py | 2 +- 11 files changed, 39 insertions(+), 39 deletions(-) diff --git a/nbconvert/exporters/html.py b/nbconvert/exporters/html.py index 0a155620c..f51e15fbd 100644 --- a/nbconvert/exporters/html.py +++ b/nbconvert/exporters/html.py @@ -268,7 +268,9 @@ def from_notebook_node( # type:ignore[explicit-override, override] resources = self._init_resources(resources) if resources is None: 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/slides.py b/nbconvert/exporters/slides.py index 62a11402b..e571a90c0 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 0f551b069..01b449657 100644 --- a/nbconvert/exporters/templateexporter.py +++ b/nbconvert/exporters/templateexporter.py @@ -203,9 +203,9 @@ 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 = "" @@ -288,7 +288,8 @@ 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( diff --git a/nbconvert/filters/ansi.py b/nbconvert/filters/ansi.py index ac91fc89f..a9882e10e 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 e078ceed0..0db092a42 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 034b82466..46a87f436 100644 --- a/nbconvert/filters/markdown_mistune.py +++ b/nbconvert/filters/markdown_mistune.py @@ -23,7 +23,7 @@ from nbconvert.filters.strings import add_anchor try: # for Mistune >= 3.0 - from mistune import (# type:ignore[attr-defined] + from mistune import ( # type:ignore[attr-defined] BlockParser, BlockState, HTMLRenderer, @@ -38,7 +38,7 @@ except ImportError: # for Mistune >= 2.0 import re - from mistune import (# type: ignore[attr-defined] + from mistune import ( # type: ignore[attr-defined] PLUGINS, BlockParser, HTMLRenderer, @@ -269,13 +269,13 @@ class IPythonRenderer(HTMLRenderer): def __init__( self, - escape: bool=True, - allow_harmful_protocols: bool=True, - embed_images: bool=False, - exclude_anchor_links: bool=False, - anchor_link_text: str="¶", - path: str="", - attachments: Optional[Dict[str, Dict[str, str]]]=None, + escape: bool = True, + allow_harmful_protocols: bool = True, + embed_images: bool = False, + exclude_anchor_links: bool = False, + anchor_link_text: str = "¶", + path: str = "", + attachments: Optional[Dict[str, Dict[str, str]]] = None, ): """Initialize the renderer.""" super().__init__(escape, allow_harmful_protocols) @@ -288,7 +288,7 @@ def __init__( else: self.attachments = {} - def block_code(self, code: str, info: Optional[str]=None) -> str: + def block_code(self, code: str, info: Optional[str] = None) -> str: """Handle block code.""" lang: Optional[str] = "" lexer: Optional[Lexer] = None @@ -361,7 +361,7 @@ def inline_math(self, body: str) -> str: """Handle inline math.""" return f"${self.escape_html(body)}$" - def image(self, text: str, url: str, title: Optional[str]=None) -> str: + def image(self, text: str, url: str, title: Optional[str] = None) -> str: """Rendering a image with title and text. :param text: alt text of the image. @@ -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}" @@ -464,9 +464,9 @@ class MarkdownWithMath(Markdown): def __init__( self, renderer: HTMLRenderer, - block: Optional[BlockParser]=None, - inline: Optional[InlineParser]=None, - plugins: Optional[Iterable[MarkdownPlugin]]=None, + block: Optional[BlockParser] = None, + inline: Optional[InlineParser] = None, + plugins: Optional[Iterable[MarkdownPlugin]] = None, ): """Initialize the parser.""" if block is None: @@ -506,7 +506,7 @@ 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""" + """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 = [] @@ -514,14 +514,14 @@ def extract_titles_from_markdown_input(markdown_input): 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 """ for __, title in headings: children = title["children"] attrs = title["attrs"] raw_text = children[0]["raw"] header_level = attrs["level"] - id = raw_text.replace(' ', '-') + id = raw_text.replace(" ", "-") 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 d80339123..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)", ), } ) @@ -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 -%}