diff --git a/mdformat_mkdocs/__init__.py b/mdformat_mkdocs/__init__.py index 4e89b40..87184f2 100644 --- a/mdformat_mkdocs/__init__.py +++ b/mdformat_mkdocs/__init__.py @@ -1,6 +1,6 @@ """An mdformat plugin for mkdocs.""" -__version__ = "2.0.0" +__version__ = "2.0.0rc4" # FYI see source code for available interfaces: # https://github.com/executablebooks/mdformat/blob/5d9b573ce33bae219087984dd148894c774f41d4/src/mdformat/plugins.py diff --git a/mdformat_mkdocs/_copy_of_mdformat_gfm/plugin.py b/mdformat_mkdocs/_copy_of_mdformat_gfm/plugin.py index ffbf78d..b20f86c 100644 --- a/mdformat_mkdocs/_copy_of_mdformat_gfm/plugin.py +++ b/mdformat_mkdocs/_copy_of_mdformat_gfm/plugin.py @@ -1,3 +1,9 @@ +"""Copied from . + +Will be removed when released (Workaround for https://github.com/hukkin/mdformat-gfm/issues/31) + +""" + import re import mdformat.plugins @@ -29,7 +35,7 @@ def update_mdit(mdit: MarkdownIt) -> None: def _strikethrough_renderer(node: RenderTreeNode, context: RenderContext) -> str: content = "".join(child.render(context) for child in node.children) - return "~~" + content + "~~" + return f"~~{content}~~" def _render_with_default_renderer(node: RenderTreeNode, context: RenderContext) -> str: @@ -47,9 +53,9 @@ def _render_with_default_renderer(node: RenderTreeNode, context: RenderContext) def _is_task_list_item(node: RenderTreeNode) -> bool: - assert node.type == "list_item" + assert node.type == "list_item" # noqa: S101 classes = node.attrs.get("class", "") - assert isinstance(classes, str) + assert isinstance(classes, str) # noqa: S101 return "task-list-item" in classes @@ -61,10 +67,10 @@ def _list_item_renderer(node: RenderTreeNode, context: RenderContext) -> str: # tasks are annotated by html. We need to remove the HTML. paragraph_node = node.children[0] inline_node = paragraph_node.children[0] - assert inline_node.type == "inline" - assert inline_node.children, "inline token must have children" + assert inline_node.type == "inline" # noqa: S101 + assert inline_node.children, "inline token must have children" # noqa: S101 html_inline_node = inline_node.children[0] - assert 'class="task-list-item-checkbox"' in html_inline_node.content + assert 'class="task-list-item-checkbox"' in html_inline_node.content # noqa: S101 # This is naughty, shouldn't mutate and rely on `.remove` here inline_node.children.remove(html_inline_node) @@ -98,7 +104,7 @@ def _postprocess_inline(text: str, node: RenderTreeNode, context: RenderContext) if not isinstance(wrap_mode, int): return text if ( - node.parent + node.parent # noqa: PLR0916 and node.parent.type == "paragraph" and not node.parent.previous_sibling and node.parent.parent @@ -106,8 +112,7 @@ def _postprocess_inline(text: str, node: RenderTreeNode, context: RenderContext) and _is_task_list_item(node.parent.parent) ): text = text.lstrip("\x00") - text = text.lstrip() - text = "xxxx" + text + text = f"xxxx{text.lstrip()}" return text @@ -115,7 +120,7 @@ def _link_renderer(node: RenderTreeNode, context: RenderContext) -> str: """Extend the default link renderer to handle linkify links.""" if node.markup == "linkify": autolink_url = node.attrs["href"] - assert isinstance(autolink_url, str) + assert isinstance(autolink_url, str) # noqa: S101 startswith_scheme = RE_COMMONMARK_URL_SCHEME.match(autolink_url) if startswith_scheme and not node.children[0].content.startswith( startswith_scheme.group(), @@ -127,11 +132,13 @@ def _link_renderer(node: RenderTreeNode, context: RenderContext) -> str: return _render_with_default_renderer(node, context) -def _escape_text(text: str, node: RenderTreeNode, context: RenderContext) -> str: +def _escape_text( + text: str, + node: RenderTreeNode, # noqa: ARG001 + context: RenderContext, # noqa: ARG001 +) -> str: # Escape strikethroughs - text = text.replace("~~", "\\~~") - - return text + return text.replace("~~", "\\~~") RENDERERS = { @@ -139,4 +146,7 @@ def _escape_text(text: str, node: RenderTreeNode, context: RenderContext) -> str "list_item": _list_item_renderer, "link": _link_renderer, } -POSTPROCESSORS = {"text": _escape_text, "inline": _postprocess_inline} +POSTPROCESSORS = { + "text": _escape_text, + "inline": _postprocess_inline, +} diff --git a/tests/fixtures-semantic-indent.md b/tests/fixtures-semantic-indent.md index 9b39dca..702e54a 100644 --- a/tests/fixtures-semantic-indent.md +++ b/tests/fixtures-semantic-indent.md @@ -258,9 +258,9 @@ Table |:---------------|---------:|:---------------------| | Name | 2| | . -| Label | Rating | Comment | -|:---------------|---------:|:---------------------| -| Name | 2| | +| Label | Rating | Comment | +| :---- | -----: | :--------------- | +| Name | 2 | | . Floating Link diff --git a/tests/format/test_parsed_result.py b/tests/format/test_parsed_result.py index 07c5e0f..66b01a2 100644 --- a/tests/format/test_parsed_result.py +++ b/tests/format/test_parsed_result.py @@ -3,7 +3,7 @@ import pytest from markdown_it.utils import read_fixture_file -from mdformat_mkdocs._normalize_list import parse_text +from mdformat_mkdocs._normalize_list import parse_text # noqa: PLC2701 FIXTURE_PATH = Path(__file__).parent / "fixtures/parsed_result.md" fixtures = read_fixture_file(FIXTURE_PATH) diff --git a/tests/helpers.py b/tests/helpers.py index 8b54cb9..9c56002 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -1,4 +1,4 @@ -from mdformat_mkdocs._helpers import separate_indent +from mdformat_mkdocs._helpers import separate_indent # noqa: PLC2701 _SHOW_TEXT = True # PLANNED: Make configurable based on pytest CLI diff --git a/tests/pre-commit-test-numbered.md b/tests/pre-commit-test-numbered.md index 612ec1d..86722c6 100644 --- a/tests/pre-commit-test-numbered.md +++ b/tests/pre-commit-test-numbered.md @@ -6,6 +6,6 @@ list item 2 2. If you store artifacts in the repository, you need to remember to - compile the application before - every commit. + compile the application before every + commit. 3. Compiled application.