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 7, 2024
1 parent 2f911f7 commit d23f2be
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 26 deletions.
4 changes: 3 additions & 1 deletion nbconvert/exporters/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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
9 changes: 5 additions & 4 deletions nbconvert/exporters/templateexporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<memory>"
Expand Down Expand Up @@ -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(
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
10 changes: 5 additions & 5 deletions nbconvert/filters/markdown_mistune.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -501,24 +501,24 @@ def heading(self, text, level):
self.headings.append((level, text))
return "" # We return an empty string to avoid outputting the headings

def extract_titles (renderer):

def extract_titles(renderer):
mistune.create_markdown(renderer=renderer)


def extract_titles_from_markdown_input(markdown_input):
# Markdown_input is a single string with all the markdown content concatenated
titles_array = []
renderer = HeadingExtractor()
extract_titles(markdown_input)
headings = renderer.headings


for item, 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
9 changes: 3 additions & 6 deletions nbconvert/nbconvertapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
),
}
)
Expand Down Expand Up @@ -678,6 +674,7 @@ def initialize(self, argv=None):
def _default_export_format(self):
return "html"


# -----------------------------------------------------------------------------
# Main entry point
# -----------------------------------------------------------------------------
Expand Down
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
2 changes: 1 addition & 1 deletion share/templates/latex/base.tex.j2
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ override this.-=))
((* endblock header *))

((* block body *))

\begin{document}
((* block predoc *))
((* block maketitle *))\maketitle((* endblock maketitle *))
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) :])
)
2 changes: 1 addition & 1 deletion tests/exporters/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def test_javascript_injection(self):
(output, resources) = HTMLExporter(
template_name=template, sanitize_html=True
).from_filename(self._get_notebook("notebook_inject.ipynb"))

assert "<script>alert('markdown cell')</script>" not in output
assert "<script>alert('text/markdown output')</script>" not in output
assert "<script>alert('text/html output')</script>" not in output
Expand Down

0 comments on commit d23f2be

Please sign in to comment.