diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6423ef8..c0c79f1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -48,6 +48,6 @@ jobs: - name: Install ruff run: python -m pip install ruff - name: Run ruff check - run: ruff check --select F,E,W,I,UP --target-version py310 . + run: ruff check --select F,E,W,I,UP,COM --target-version py310 . - name: Run ruff format run: ruff format --diff . diff --git a/markup2html.py b/markup2html.py index 6f030a7..d24e588 100755 --- a/markup2html.py +++ b/markup2html.py @@ -27,7 +27,9 @@ def export_file(args: argparse.Namespace) -> None: if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument( - "--web-environment", help="export for web environment", action="store_true" + "--web-environment", + help="export for web environment", + action="store_true", ) parser.add_argument( "--include-stylesheet", @@ -35,7 +37,9 @@ def export_file(args: argparse.Namespace) -> None: action="store_true", ) parser.add_argument( - "--fallback-title", help="fallback title of the HTML document", metavar="TITLE" + "--fallback-title", + help="fallback title of the HTML document", + metavar="TITLE", ) parser.add_argument("input_file", help="input file") parser.add_argument("output_file", help="output file") diff --git a/markups/__init__.py b/markups/__init__.py index 053b1d2..4cc2a6a 100644 --- a/markups/__init__.py +++ b/markups/__init__.py @@ -59,18 +59,21 @@ def get_available_markups() -> list[type[AbstractMarkup]]: @overload def get_markup_for_file_name( - filename: str, return_class: Literal[False] = False + filename: str, + return_class: Literal[False] = False, ) -> AbstractMarkup | None: ... @overload def get_markup_for_file_name( - filename: str, return_class: Literal[True] + filename: str, + return_class: Literal[True], ) -> type[AbstractMarkup] | None: ... def get_markup_for_file_name( - filename: str, return_class: bool = False + filename: str, + return_class: bool = False, ) -> AbstractMarkup | type[AbstractMarkup] | None: """ :param filename: name of the file diff --git a/markups/abstract.py b/markups/abstract.py index 7f70419..be594cf 100644 --- a/markups/abstract.py +++ b/markups/abstract.py @@ -64,7 +64,11 @@ class ConvertedMarkup: """ def __init__( - self, body: str, title: str = "", stylesheet: str = "", javascript: str = "" + self, + body: str, + title: str = "", + stylesheet: str = "", + javascript: str = "", ): self.title = title self.stylesheet = stylesheet diff --git a/markups/markdown.py b/markups/markdown.py index 4021f69..2808dbc 100644 --- a/markups/markdown.py +++ b/markups/markdown.py @@ -95,7 +95,8 @@ def available() -> bool: return getattr(markdown, "__version_info__", (2,)) >= (3,) def _load_extensions_list_from_txt_file( - self, filename: str + self, + filename: str, ) -> Iterator[_name_and_config]: with open(filename) as extensions_file: for line in extensions_file: @@ -103,7 +104,8 @@ def _load_extensions_list_from_txt_file( yield self._split_extension_config(line.rstrip()) def _load_extensions_list_from_yaml_file( - self, filename: str + self, + filename: str, ) -> Iterator[_name_and_config]: with open(filename) as extensions_file: try: @@ -119,7 +121,8 @@ def _load_extensions_list_from_yaml_file( yield item, {} def _get_global_extensions( - self, filename: str | None + self, + filename: str | None, ) -> Iterator[_name_and_config]: local_directory = os.path.dirname(filename) if filename else "" choices = [ @@ -171,7 +174,8 @@ def _split_extension_config(self, extension_name: str) -> _name_and_config: return extension_name, {x.strip(): y.strip() for (x, y) in pairs} def _split_extensions_configs( - self, extensions: Iterable[str] + self, + extensions: Iterable[str], ) -> Iterator[_name_and_config]: """Splits the configuration options from a list of strings. @@ -181,7 +185,8 @@ def _split_extensions_configs( yield self._split_extension_config(extension) def _apply_extensions( - self, document_extensions: Iterable[_name_and_config] | None = None + self, + document_extensions: Iterable[_name_and_config] | None = None, ) -> None: extensions = self.global_extensions.copy() extensions.extend(self._split_extensions_configs(self.requested_extensions)) @@ -207,7 +212,8 @@ def _apply_extensions( candidate = self._canonicalize_extension_name(name) if candidate is None: warnings.warn( - f'Extension "{name}" does not exist.', ImportWarning + f'Extension "{name}" does not exist.', + ImportWarning, ) continue canonical_name = candidate @@ -223,7 +229,9 @@ def _apply_extensions( self.extension_configs = extension_configs def __init__( - self, filename: str | None = None, extensions: list[str] | None = None + self, + filename: str | None = None, + extensions: list[str] | None = None, ): AbstractMarkup.__init__(self, filename) import markdown diff --git a/markups/restructuredtext.py b/markups/restructuredtext.py index 449d887..b8a6145 100644 --- a/markups/restructuredtext.py +++ b/markups/restructuredtext.py @@ -21,7 +21,12 @@ class CustomHTMLTranslator(HTMLTranslator): # type: ignore def starttag( # type: ignore - self, node, tagname, suffix="\n", empty=False, **attributes + self, + node, + tagname, + suffix="\n", + empty=False, + **attributes, ): if getattr(node, "line", None) is not None: attributes["data-posmap"] = node.line @@ -65,7 +70,7 @@ def __init__( "syntax_highlight": "short", "halt_level": 5, # Never convert system messages to exceptions "stylesheet_path": "minimal.css", # Do not include plain.css - } + }, ) AbstractMarkup.__init__(self, filename) self.writer = Writer() diff --git a/tests/test_asciidoc.py b/tests/test_asciidoc.py index 790c53f..b901002 100644 --- a/tests/test_asciidoc.py +++ b/tests/test_asciidoc.py @@ -8,7 +8,8 @@ @unittest.skipUnless( - AsciiDocMarkup.available(), "asciidoc.py and/or lxml not available" + AsciiDocMarkup.available(), + "asciidoc.py and/or lxml not available", ) class AsciiDocTextTest(unittest.TestCase): def test_basic(self) -> None: @@ -26,7 +27,8 @@ def test_basic(self) -> None: def test_error_handling(self) -> None: markup = AsciiDocMarkup() with self.assertWarnsRegex( - SyntaxWarning, "section title not allowed in list item" + SyntaxWarning, + "section title not allowed in list item", ): converted = markup.convert(INVALID_SYNTAX) self.assertIn("Foo", converted.get_document_body()) diff --git a/tests/test_markdown.py b/tests/test_markdown.py index b3df361..4ef50ce 100644 --- a/tests/test_markdown.py +++ b/tests/test_markdown.py @@ -159,11 +159,12 @@ def test_extensions_loading(self) -> None: markup = MarkdownMarkup() self.assertIsNone(markup._canonicalize_extension_name("nonexistent")) self.assertIsNone( - markup._canonicalize_extension_name("nonexistent(someoption)") + markup._canonicalize_extension_name("nonexistent(someoption)"), ) self.assertIsNone(markup._canonicalize_extension_name(".foobar")) self.assertEqual( - markup._canonicalize_extension_name("meta"), "markdown.extensions.meta" + markup._canonicalize_extension_name("meta"), + "markdown.extensions.meta", ) name, parameters = markup._split_extension_config("toc(anchorlink=1, foo=bar)") self.assertEqual(name, "toc") @@ -181,7 +182,7 @@ def test_loading_extensions_by_module_name(self) -> None: def test_removing_duplicate_extensions(self) -> None: markup = MarkdownMarkup( - extensions=["remove_extra", "toc", "markdown.extensions.toc"] + extensions=["remove_extra", "toc", "markdown.extensions.toc"], ) self.assertEqual(len(markup.extensions), 1) self.assertIn("markdown.extensions.toc", markup.extensions) @@ -209,7 +210,7 @@ def test_document_extensions_parameters(self) -> None: " toc(title=Table of contents, baselevel=3) wikilinks --->\n\n" ) html = markup.convert( - toc_header + "[TOC]\n\n# Header\n[[Link]]" + toc_header + "[TOC]\n\n# Header\n[[Link]]", ).get_document_body() self.assertEqual( html, @@ -248,7 +249,7 @@ def test_remove_extra(self) -> None: def test_remove_extra_document_extension(self) -> None: markup = MarkdownMarkup(extensions=[]) html = markup.convert( - "Required-Extensions: remove_extra\n\n" + tables_source + "Required-Extensions: remove_extra\n\n" + tables_source, ).get_document_body() self.assertNotIn("