diff --git a/nbconvert/exporters/html.py b/nbconvert/exporters/html.py index b56a2c24f..bee8a8968 100644 --- a/nbconvert/exporters/html.py +++ b/nbconvert/exporters/html.py @@ -5,7 +5,6 @@ import base64 import json -from lxml.html.clean import clean_html import mimetypes import os from pathlib import Path diff --git a/nbconvert/exporters/templateexporter.py b/nbconvert/exporters/templateexporter.py index 4f8a03e88..e0c60ef36 100644 --- a/nbconvert/exporters/templateexporter.py +++ b/nbconvert/exporters/templateexporter.py @@ -6,9 +6,8 @@ # Distributed under the terms of the Modified BSD License. -import json import html -from lxml.html.clean import clean_html +import json import os import uuid import warnings @@ -23,6 +22,7 @@ TemplateNotFound, ) from jupyter_core.paths import jupyter_path +from lxml.html.clean import clean_html from traitlets import Bool, Dict, HasTraits, List, Unicode, default, observe, validate from traitlets.config import Config from traitlets.utils.importstring import import_item diff --git a/nbconvert/exporters/tests/test_html.py b/nbconvert/exporters/tests/test_html.py index 6a43c709d..56c4dec25 100644 --- a/nbconvert/exporters/tests/test_html.py +++ b/nbconvert/exporters/tests/test_html.py @@ -137,9 +137,9 @@ def test_basic_name(self): def test_javascript_injection(self): for template in ["lab", "classic", "reveal"]: - (output, resources) = HTMLExporter( - template_name=template - ).from_filename(self._get_notebook('notebook_inject.ipynb')) + (output, resources) = HTMLExporter(template_name=template).from_filename( + self._get_notebook("notebook_inject.ipynb") + ) # Check injection in the metadata.title of the Notebook assert "" not in output @@ -170,14 +170,17 @@ def test_javascript_injection(self): assert "" not in output # Check injection in widget view - assert "" in output assert "" in output @@ -187,9 +190,8 @@ def test_javascript_injection(self): # But it's an opt-out for template in ["lab", "classic", "reveal"]: (output, resources) = HTMLExporter( - template_name=template, - sanitize_html=True - ).from_filename(self._get_notebook('notebook_inject.ipynb')) + template_name=template, sanitize_html=True + ).from_filename(self._get_notebook("notebook_inject.ipynb")) assert "" not in output assert "" not in output diff --git a/nbconvert/filters/highlight.py b/nbconvert/filters/highlight.py index e48946df5..40ed574df 100644 --- a/nbconvert/filters/highlight.py +++ b/nbconvert/filters/highlight.py @@ -68,7 +68,9 @@ def __call__(self, source, language=None, metadata=None): return _pygments_highlight( source if len(source) > 0 else " ", # needed to help post processors: - HtmlFormatter(cssclass=escape(f" highlight hl-{language}"), **self.extra_formatter_options), + HtmlFormatter( + cssclass=escape(f" highlight hl-{language}"), **self.extra_formatter_options + ), language, metadata, ) diff --git a/nbconvert/filters/tests/test_highlight.py b/nbconvert/filters/tests/test_highlight.py index da224323f..08c734460 100644 --- a/nbconvert/filters/tests/test_highlight.py +++ b/nbconvert/filters/tests/test_highlight.py @@ -77,7 +77,7 @@ def test_parse_html_many_lang(self): @pytest.mark.filterwarnings("ignore") def test_inject_html(self): out = highlight2html(self.tests[0], 'ipython3-foo">') - assert '' not in out + assert "" not in out def _extract_tokens(self, root, cls): return set(map(lambda x: x.text, root.findall(".//*[@class='" + cls + "']"))) diff --git a/nbconvert/tests/test_nbconvertapp.py b/nbconvert/tests/test_nbconvertapp.py index f01466a34..d02be3d39 100644 --- a/nbconvert/tests/test_nbconvertapp.py +++ b/nbconvert/tests/test_nbconvertapp.py @@ -374,7 +374,7 @@ def test_no_input(self): '= ' 'symbols' '(' - '\'x y z\'' + "'x y z'" ')' ) not in text self.nbconvert("notebook1.ipynb --log-level 0 --to html") @@ -392,7 +392,7 @@ def test_no_input(self): '= ' 'symbols' '(' - '\'x y z\'' + "'x y z'" ')' ) in text2