diff --git a/mdformat_mkdocs/__init__.py b/mdformat_mkdocs/__init__.py index 606ab2f..3addf31 100644 --- a/mdformat_mkdocs/__init__.py +++ b/mdformat_mkdocs/__init__.py @@ -1,6 +1,6 @@ """An mdformat plugin for mkdocs.""" -__version__ = "2.0.7" +__version__ = "2.0.8" # FYI see source code for available interfaces: # https://github.com/executablebooks/mdformat/blob/5d9b573ce33bae219087984dd148894c774f41d4/src/mdformat/plugins.py diff --git a/mdformat_mkdocs/_normalize_list.py b/mdformat_mkdocs/_normalize_list.py index 1e7634b..f4492a7 100644 --- a/mdformat_mkdocs/_normalize_list.py +++ b/mdformat_mkdocs/_normalize_list.py @@ -238,9 +238,12 @@ class ParsedText(NamedTuple): debug_block_indents: list[BlockIndent | None] -def format_new_content(line: LineResult, inc_numbers: bool) -> str: +def format_new_content(line: LineResult, inc_numbers: bool, is_code: bool) -> str: new_content = line.parsed.content - if line.parsed.syntax in {Syntax.LIST_BULLETED, Syntax.LIST_NUMBERED}: + if not is_code and line.parsed.syntax in { + Syntax.LIST_BULLETED, + Syntax.LIST_NUMBERED, + }: list_match = RE_LIST_ITEM.fullmatch(line.parsed.content) assert list_match is not None # for pyright # noqa: S101 new_bullet = "-" @@ -263,7 +266,10 @@ def parse_text(text: str, inc_numbers: bool) -> ParsedText: block_indents = [_c or _h for _c, _h in zip_equal(code_indents, html_indents)] new_indents = list(starmap(format_new_indent, zip_equal(lines, block_indents))) - new_contents = [format_new_content(line, inc_numbers) for line in lines] + new_contents = [ + format_new_content(line, inc_numbers, ci is not None) + for line, ci in zip_equal(lines, code_indents) + ] return ParsedText( lines=lines, new_lines=[*zip_equal(new_indents, new_contents)], @@ -276,6 +282,8 @@ def parse_text(text: str, inc_numbers: bool) -> ParsedText: class SemanticIndent(Enum): + """Possible states for evaluating semantic indents. The values aren't relevant.""" + INITIAL = "Hack for MyPy and map_lookack, which returns initial..." EMPTY = "" ONE_LESS_ON_NEXT = "⤓(←)" @@ -285,6 +293,7 @@ class SemanticIndent(Enum): def parse_semantic_indent(last: SemanticIndent, line: LineResult) -> SemanticIndent: + """Conditionally evaluate when semantic indents are necessary.""" # TODO: This works, but is very confusing if not line.parsed.content: result = SemanticIndent.EMPTY @@ -346,6 +355,7 @@ def normalize_list( context: RenderContext, check_if_align_semantic_breaks_in_lists: Callable[[], bool], # Attach with partial ) -> str: + """Format markdown list.""" # FIXME: Is this filter working correctly? # If it is, the test for "Formats non-root lists" should be failing if node.level > 1: diff --git a/tests/format/fixtures/text.md b/tests/format/fixtures/text.md index 17e9965..55d0f1a 100644 --- a/tests/format/fixtures/text.md +++ b/tests/format/fixtures/text.md @@ -1457,3 +1457,18 @@ Without CLI argument, does not support Python mkdocstring cross-references (http \[package.module.object\]\[\] \[Object\]\[package.module.object\] . + +Do not format lists in code blocks +. +* Item 1 + + ```text + * sample plain text block. + ``` +. +- Item 1 + + ```text + * sample plain text block. + ``` +.