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 Oct 25, 2024
1 parent 6fbb968 commit c799885
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion nbconvert/exporters/slides.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <section> elements in the HTML, subslides (the vertically
Expand Down
2 changes: 1 addition & 1 deletion nbconvert/filters/ansi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, ""

Expand Down
2 changes: 1 addition & 1 deletion nbconvert/filters/citation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down
28 changes: 15 additions & 13 deletions nbconvert/filters/markdown_mistune.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
import bs4
import mistune
from mistune.renderers.markdown import MarkdownRenderer
from nbformat import NotebookNode
from pygments import highlight
from pygments.formatters import HtmlFormatter
from pygments.lexer import Lexer
from pygments.lexers import get_lexer_by_name
from pygments.util import ClassNotFound

from nbconvert.filters.strings import add_anchor
from nbformat import NotebookNode

try: # for Mistune >= 3.0
from mistune import ( # type:ignore[attr-defined]
Expand Down Expand Up @@ -386,7 +386,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}"
Expand Down Expand Up @@ -516,31 +516,33 @@ def extract_titles_from_notebook_node(nb: NotebookNode):
if cell.cell_type == "markdown":
lines = cell.source.splitlines()
for line in lines:
if line.startswith('#') and line.count('#') != 1: # exclude the main title to build the table of content
if (
line.startswith("#") and line.count("#") != 1
): # exclude the main title to build the table of content
markdown_collection = markdown_collection + line.strip() + "\n"
if line.startswith('<h2>'):
if line.startswith("<h2>"):
line = line.replace("<h2>", "# ")
if line.startswith('<h3>'):
if line.startswith("<h3>"):
line = line.replace("<h3>", "# ")
if line.startswith('<h4>'):
if line.startswith("<h4>"):
line = line.replace("<h4>", "# ")
if line.startswith('<h5>'):
if line.startswith("<h5>"):
line = line.replace("<h5>", "# ")
if line.startswith('<h6>'):
if line.startswith("<h6>"):
line = line.replace("<h6>", "# ")
if '</h2>' in line:
if "</h2>" in line:
line = line.replace("</h2>", "")
markdown_collection = markdown_collection + line.strip() + "\n"
if '</h3>' in line:
if "</h3>" in line:
line = line.replace("</h3>", "")
markdown_collection = markdown_collection + line.strip() + "\n"
if '</h4>' in line:
if "</h4>" in line:
line = line.replace("</h4>", "")
markdown_collection = markdown_collection + line.strip() + "\n"
if '</h5>' in line:
if "</h5>" in line:
line = line.replace("</h5>", "")
markdown_collection = markdown_collection + line.strip() + "\n"
if '</h6>' in line:
if "</h6>" in line:
line = line.replace("</h6>", "")
markdown_collection = markdown_collection + line.strip() + "\n"

Expand Down
8 changes: 4 additions & 4 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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) :])
)

0 comments on commit c799885

Please sign in to comment.